我被一些简单的事情困住了。当我发出 ajax 请求时,由于某些原因它没有足够的时间来分配combonews
变量:
jQuery.ajax({
type: "POST",
url: "People.aspx/LoadComboNews",
data: "{\"id\":" + usrid + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// Replace the div's content with the page method's return.
combonews = '';
setTimeout(function () { combonews = eval(msg.d); }, 500);
//combonews = eval(msg.d);
}
});
尝试添加 setTimeout 如图所示,但是当我想提醒combonews
它为空时。当我发出警报msg.d
时,它总是准备好数据。有没有办法延长执行时间combonews = eval(msg.d);
?
更新:
当我通过绑定到按钮单击事件来运行它时,分配工作正常
--------------------------------------
更新2
function lcombo() {
jQuery('#combostart ~ option').remove();
//setTimeout((function () {
jQuery.ajax({
type: "POST",
url: "People.aspx/LoadComboNews",
data: "{\"id\":" + usrid + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
complete: function (msg) {
// Replace the div's content with the page method's return.
combonews = '';
//setTimeout(function () { combonews = eval(msg.d); }, 500);
combonews = JSON.parse(msg.d);
}
});
//combonews = eval(combonews);
//alert(combonews);
jQuery(".chzn-select").chosen();
jQuery(".chzn-select-deselect").chosen({ allow_single_deselect: true });
var str = "";
if (combonews.length > 0)
for (var i in combonews) {
str += "<option value='" + combonews[i][0] + "'>" + combonews[i][1] + "</option>";
}
jQuery("#combooptions").append(str);
jQuery("#combooptions").val(draftid);
jQuery("#combooptions").trigger("liszt:updated");
}
然后我加载 lcombo() 函数。它在点击时起作用,但在其他一些后果中不起作用(我的意思是不会将消息加载到组合新闻中)
感谢您