如何使用jQuery.get()解析返回的页面html [英] how to parse returned page html with jQuery.get()
问题描述
直到最近我还是使用$.load()
来获取另一页的特定页面并将其加载到当前页面中,但是当用户发起这些请求时,他们可以排队,我发现自己需要一种方法来中止它们,以免单击-满意的用户破坏了我的页面.
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.
这导致我进入$.get()
,效果很好,如果在第一次返回之前启动了另一个请求,我可以中止该请求,但是现在我需要解析返回的html(这是带有doc-type和head元素的整个页面)并且只能从中得到一个div.
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 div from it.
我该如何实现?
推荐答案
这应该有效:
$.get('ajax/test.html', function(data) {
var my_div = $('#my_div', $(data));
});
这篇关于如何使用jQuery.get()解析返回的页面html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!