ajax async: true statement execution order

174 views Asked by At

I have the following Ajax,I want to know when call back method of 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;  

I know statement 1 to statement 5 will execute in order. As async: true, statement 8; will execute next, my question is

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??

1

There are 1 answers

1
marekful On

First, async: true is the default, no need to specify. Statement 6 will execute as soon as a success response comes back from the ajax request. It depends on many factors how much time it will take. Statement 7 will execute right after statement 6.