+ -
当前位置:首页 → 问答吧 → jQuery 异步加载问题

jQuery 异步加载问题

时间:2011-08-31

来源:互联网

$(document).ready(function() {
userList();
  alert(hashUser.size());
});

function userList() {
$.ajax({
type : "POST",
dataType : "json",
url : "ScoreJson/listClassmates.action",
success : function(data) {
$.each(data.userList, function(i, item) {
hashUser.add(item.userId, item.realName);
});

},
error : function() {
alert("action_error");
}
});
}

请教童鞋们 hashUser.size() 怎么总是为0呢 明明是有数据的 是不是异步加载的数据在$(document).ready不能立即获得到,有没有什么解决方案呢

作者: peakcary   发布时间: 2011-08-31

function userList() {
$.ajax({
type : "POST",
dataType : "json",
url : "ScoreJson/listClassmates.action",
success : function(data) {
$.each(data.userList, function(i, item) {
hashUser.add(item.userId, item.realName);
});
alert(hashUser.size());
},
error : function() {
alert("action_error");
}
});
}

你都说是异步的了

作者: ly89924   发布时间: 2011-08-31

怎么可能立即获得

作者: ly89924   发布时间: 2011-08-31

是的,不然就不是异步了,有需求的情况下可以改成同步

作者: pj100   发布时间: 2011-08-31