我有以下Ajax
,我想知道异步Ajax调用的
。 回调方法
何时开始执行
statement 1;
statement 2;
statement 3;
statement 4;
statement 5;
jQuery.ajax({
url: "/includes/unit.jsp?" + params,
cache: false,
dataType: "html",
async: true,
success: function (html) {
statement 6;
statement 7;
}
});
statement 8;
statement 9;
statement 10;
statement 11;
.
.
.
statement 10000;
我知道语句 1 到语句 5
将按顺序执行。由于 async: true
,statement 8;
接下来将执行,我的问题是
when will
statement 6; and statement 7;
execute, will it execute all the statements after theajax call
tillstatement 10000
then executesuccess method
. or at some point it got the response from server while executingstatement 500
, executesuccess method
then start executingstatement 501
??
最佳答案
首先,async: true
是默认的,不需要指定。一旦 ajax 请求返回成功响应,语句 6 将立即执行。这取决于很多因素,需要多少时间。语句 7 将在语句 6 之后立即执行。
关于jquery - ajax异步: true statement execution order,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30725542/