ajax async:true语句执行顺序

时间:2015-06-09 07:27:23

标签: jquery ajax asynchronous

我有以下Ajax,我想知道call back method asynchronous Ajax call start execution的时间。

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;  

我知道statement 1 to statement 5将按顺序执行。作为async: truestatement 8;将会执行,我的问题是

  

statement 6; and statement 7;执行时,它会执行ajax callstatement 10000之后的所有语句,然后执行success method。或者在某些时候它在执行statement 500时得到了服务器的响应,执行success method然后开始执行statement 501 ??

1 个答案:

答案 0 :(得分:0)

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

相关问题