jQuery的AJAX着的环通的发现数据 [英] jquery ajax cant loop thru the found data
本文介绍了jQuery的AJAX着的环通的发现数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要环通其装有AJAX的文件,但它不会循环,我已经尝试了几件事情,但我不能让它的工作。
// jQuery的
$。阿贾克斯({
网址:'file.html',
键入:GET,
数据类型:HTML,
成功:功能(数据){
$(数据).find('格')。每个(函数(一){
警报('发现')
});
},
错误:函数(){
警报('OEPS ......)
}
});
// file.html
< DIV>
//内容放在这里
< / DIV>
< DIV>
//内容放在这里
< / DIV>
< DIV>
//内容放在这里
< / DIV>
...
...
解决方案
您需要修改 .find
到 .filter
。这是因为 .find
搜索<打击>孩子一击>所有的元素的后代,但由于你的HTML文件仅仅是&LT; DIV&GT ;
S,则需要使用 .filter
找到他们。
演示: http://jsfiddle.net/zuPVp/
I want to loop thru a file which is loaded with ajax, but it won't loop, i have tried a couple of things but I cant get it to work.
// jquery
$.ajax({
url: 'file.html',
type: "GET",
dataType: "html",
success: function(data) {
$(data).find('div').each(function(i){
alert('found')
});
},
error: function(){
alert('oeps...')
}
});
// file.html
<div>
// content goes here
</div>
<div>
// content goes here
</div>
<div>
// content goes here
</div>
...
...
解决方案
You need to change .find
to .filter
. This is because .find
searches the children descendants of all the elements, but since your html file is just <div>
s, you need to use .filter
to find them.
DEMO: http://jsfiddle.net/zuPVp/
这篇关于jQuery的AJAX着的环通的发现数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文