我有一个类似的功能
function m1(){
$('.loader').show();
var xargs={
type : 'POST',
url : resourceUrls["listUrl"],
data : "sId="+sId,
async:false,
dataType : "text",
success : OnGetJsonCallback,
failure : function(response) {
$(".loader").hide();
}
};
$.ajax(xargs);
}
这里的问题是,在进行 ajax 调用之前没有显示加载程序。如果我放置一个正在记录的控制台日志语句。
我做了一些搜索,发现同步 AJAX 调用会卡住浏览器。但它可以显示加载程序然后卡住浏览器,不是吗?
最佳答案
I did some searching and got to know that synchronous AJAX calls freeze the browser. But it can show the loader and then freeze the browser isnt it?
我不同意这样做,但你可以听完整的节目,然后进行同步调用:
$('.loader').show(500, m1);
function m1(){
var xargs={
type : 'POST',
url : resourceUrls["listUrl"],
data : "sId="+sId,
async:false,
dataType : "text",
success : OnGetJsonCallback,
failure : function(response) {
$(".loader").hide();
}
};
$.ajax(xargs);
}
关于javascript - 同步 ajax 调用时未执行先前的语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37596913/