how to parse returned page html with jQuery.get()
I was until recently using $.load()
to get a specific piece of another page and load it into the current one, but as the user initiates those requests they can queue up and I found myself needing a way to abort them lest click-happy users break my page.
This led me to $.get()
which works great and lets me abort the request if another is launched before the first returns, but now I need to parse the returned html (it's an entire page with doc-type and head elements) and only get one d开发者_如何学Goiv from it.
How do I achieve this?
This should work:
$.get('ajax/test.html', function(data) {
var my_div = $('#my_div', $(data));
});
In the callback:
function(data) {
// we wrap data with jQuery here:
$(data).find("#id");
}
I tried binarious example, but it returned object::object, so modified slightly:
$.get($(this).attr("href"), function(returnedHTML) {
alert($('#content', $(returnedHTML)).html());
})
精彩评论