×

jquery异步循环获取功能实现代码

作者:Terry2017.02.12来源:Web前端之家浏览:8909评论:0
关键词:JQueryJS
html代码:
复制代码 代码如下:

<table id="repTable"……>
……
<span id="<%# Eval("Id") %>" class="address"></span>
</table>

jquery代码:

复制代码 代码如下:

$(document).ready(function(){
$("#repTable span.address").each(function(){
var spanTemp = $(this);
$.ajax({
type: "get",
url: "SceneryAjaxCall.aspx",
data: "sid="+$(this).attr("id"),
cache: true,
dataType: "html",
success: function(msg){
spanTemp.append(msg);
}
});
});
});


其中在写jquery代码时,我遇到了下面几个问题:

(1)开始没写第三行,而是在第十一行直接调用的$(this),报错“不能给回调函数赋值”。原因是回调后对象已经发生改变,所以需要事先保存;

(2)没写dataType,发现不能返回msg,不知道为什么;

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/svg1486828800552.html

网友评论文明上网理性发言已有0人参与

发表评论: