Jquery中Ready函数的多个Ajax查询
我有一张类似下图的桌子 通过Jquery中Ready函数的多个Ajax查询,jquery,document-ready,onload-event,Jquery,Document Ready,Onload Event,我有一张类似下图的桌子 通过jquery.get方法加载页面后,我想在“ROL”列中填入数据 为此,我使用下面提到的代码 $(function() { setTimeout(function() { $('.details').each(function() { locid = $(this).find('.locationId').html(); prodid = $(this).find('.productId').h
jquery.get方法加载页面后,我想在“ROL”列中填入数据
为此,我使用下面提到的代码
$(function() {
setTimeout(function() {
$('.details').each(function() {
locid = $(this).find('.locationId').html();
prodid = $(this).find('.productId').html();
alert(prodid);
roqty = $(this).find('.roqty');
$.get('myUrl', null, function(d) {
CC = JSON.parse(d);
roqty.html(CC.roqty);
});
});
}, 5000);
})
加载页面后,仅填写ROL列的最后一个单元格。请看下图
尽管警报发生了3次。
可能是什么问题?因为您已将roqty
定义为全局变量,所以在等待$.get('myUrl')
完成时,它的引用将更新到最后一个元素
将roqty
定义为作用域为each()
回调函数的局部变量
var roqty = $(this).find('.roqty');
这真是太好了。几分钟后接受你的回答。只是好奇,为什么在警报中prodid是正确的,而它也被定义为全局的?谢谢。@abbas,你已经指定了警报(prodid)
在$的回调中。每个不是$。get('myUrl'