Here is my jquery:
$.ajax({
url: hash,
success: function(data){
var thePage = $(data);
alert(data);
$('#slider_menu').html($('div#menu_bg', thePage).html());
}
});
The alert(data) returns this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Pharma Mix</title>
<link href="style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var currentX = 0;
var currentY = 0;
var pixelIncrement = 39;
var currentFrame = 0;
var currentImage = '';
$('#rotator').mousemove(function(e){
currentY = e.clientY - this.offsetTop;
currentX = e.clientX - this.offsetLeft;
currentFrame = (parseInt(currentX / pixelIncrement) + 1);
//$(this).html(currentFrame);
if(currentFrame < 12)
{
currentImage = String(currentFrame) + ".jpg"
$(this).css({'backgroundImage':'url("images/' + currentImage + '")'});
}
});
});
</script>
</head>
<body>
<div id="menu_bg">
<div id="wrapper">
<div style="height:30px; background:#009de4"></div>
<div id="homepage_menu">
<div style="float:left"><br><a href="#healthcare.php"><img src="images/hcpbutton.jpg" style="margin-right:25px"></a><a href="#pharma.php"><img src="images/pharmabutton.jpg"></a></div>
<div style="float:right"><br><img src="images/pharmamixlogo.jpg" alt=""></div>
</div> <!-- #homepage_menu -->
</div> <!-- #wrapper -->
</div> <!-- #menu_bg -->
<div id="homepage_bg">
<div id="homepage_wrapper">
<div style="text-align:center"><img src="images/homepage_heading.jpg" alt=""></div>
<div id="homepage_leftboxes">
<div class="homepage_box1">
<p class="homepage_boxtext">
"Thanks for delivering an outstanding event. Feedback has been excellent all round - in terms of programme, venue, ambiance, technical delivery and the conference team."
<br><br>
<b>Tracey Guise</b>, BSAC
</p>
</div> <!-- #homepage_box1 -->
<div class="homepage_box3">
<p class="homepage_boxtext">
The whole event ran very well - Debbie did an excellent job of keeping it all running very smoothly indeed.
<br><br>
<b>Anthony Grosso</b>, UCLH
</p>
</div> <!-- #homepage_box3 -->
</div> <!-- #homepage_leftboxes -->
<div id="rotator" style="width:430px;height:336px; float:left;" class="initalise"></div>
<div id="homepage_rightboxes">
<div class="homepage_box2">
<p class="homepage_boxtext">
"The understanding and creative thinking that Pharma Mix have demonstrated has provided some genuine and demonstratable return on investment to the Evolution brand."<br><br>
<b>Luke Rudman</b>, Evolution Homecare
</p>
</div> <!-- #homepage_box2 -->
<div class="homepage_box4">
<p class="homepage_boxtext">
"I would like to thank Debbie & her team for the excellence in the delivery of this superb website & her patience with us."
<br><br>
Kevin Palmer, Mundipharma
</p>
</div> <!-- #homepage开发者_开发问答_box4 -->
</div> <!-- #homepage_rightboxes -->
<div style="height:170px;"><img src="images/homepage_clients.jpg"></div>
</div><!-- #homepage_wrapper -->
</div><!-- #homepage_bg -->
<div style="color:white; text-align:center; padding-top:30px">Contact Us: 28b Priestgate . Peterborough . PE1 1JA . UK Tel: 01733 554472</div>
</body>
</html>
But the #menu_bg
div won't return its content! :(
This WORKS for any divs embedded further into the document (eg This will work) but I really don't have any say over the content of the page being requested.
Any ideas why this won't work? Or how to make it work?
Thank you
Can you try ?
$.ajax({
url: hash,
success: function(data){
$('#slider_menu').html($(data).filter('div#menu_bg').html());
}
});
Hope this helps.
What about finding the parent of div#wrapper
?
You could try start from body
tag.
$("body").next()
next() give you the imediately tag.
Had to change the returned code... there was no answer - it must be a bug, or similar.
Try
$('#slider_menu').html($(data).find('div#menu_bg').html());
Cheers!
精彩评论