jquery - ajax异步: true statement execution order

标签 jquery ajax asynchronous

我有以下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: truestatement 8; 接下来将执行,我的问题是

when will statement 6; and statement 7; execute, will it execute all the statements after the ajax call till statement 10000 then execute success method. or at some point it got the response from server while executing statement 500, execute success method then start executing statement 501??

最佳答案

首先,async: true是默认的,不需要指定。一旦 ajax 请求返回成功响应,语句 6 将立即执行。这取决于很多因素,需要多少时间。语句 7 将在语句 6 之后立即执行。

关于jquery - ajax异步: true statement execution order,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30725542/

相关文章:

asp.net - 添加 context.Response.Headers.Add ("Cache-Control", "no-cache");说需要 IIS 集成管道?

javascript - 是否可以在加载 jQuery 之前预先注册处理程序?

javascript - 更新 React 状态数组中的 bool 值

javascript - 检测 Bootstrap 模式窗口是否显示无法正常工作

jquery - 将加载的 CSS 应用于动态创建的 HTML

javascript - 将页面的所有媒体查询输出到一个列表中

异步读取 SSH 输出

javascript - 函数无法正确读取值

使用 ajax jquery 和 json 的 Javascript 不适用于 IE 或 chrome 帮助!

javascript - jQuery 帮助 : toggle() is not working properly