Is it possible to load an html document using ajax and then perform a jquery selection on the loaded html?
I want to perform a search against a remote search server and then use the results to reformat an existing page.
EDIT: the find function doesnt seem to return results (length is always 0). Here is the sample html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<p>Hello world</p>
<p>good bye world</p>
</body>
</html>
And here is the jQuery:
$(document).ready(function() {
$.ajax({
url: 'content/HTMLPage.htm',
dataType: 'html',
success: function(data) {
alert($(data).find('p').length);
}
});
});
I really struggled with this. I have managed to load a whole document and select from it correctly, but this one had a doctype.
Otherwise it seems it is possible but it has its caveats. The items you are selecting need to have at least a parent node. I dont really think I can mark anything off here as an answer just yet.
This html returned 2 elements: