My ajax (jquery) response (html) gives me a whole junk of html source code since it fetches the enrite page.
The response is somewhat like below:
<html>
<head>
...
...
</head>
<body>
.
.....
.
.......
<div id="content">
content i want to extract
</div>
.............
..........
.............
</body>
</html>
I need help with the following:
1) Is it possible to read just whatever is between the <div id='content'></div>? if yes, how?
2) if #1 is not possible, how could I extract just the content from the <div id='content'></div>?
The code I tried:
/*Ajax*/
$jq(function(){
alert ("Doc ready");
$jq("#content a.next-page").bind("click", function(e){
alert ("Hey!");
/*Make the call*/
$jq.ajax({
url: "/page/2",
type: "get",
cache: false,
data: "",
error: function(){alert ("No data found for your search.");},
success: function(results){
//$searchPanel.find("tbody").empty().append(results);
//$searchPanelHolder.css({"display":"block"});
alert (results.find("div[id='content']").html());
e.preventDefault();
}
});
e.preventDefault();
});
});
Any help on this is much appreciated
Many thanks,
Racky
Yes, it is possible, but you need to make a jQuery object out of it first.
Change this line:
to this:
or, better yet, to this:
EDIT:
Looks like if the element you want is a direct child of
body, you’ll need to use.filter()instead since thebodyseems to be excluded from the jQuery object. Looks like just its contents are included.