George Cristian
George Cristian

Reputation: 59

Ajax call while some code is executing

I have a pice of code that looks like that:

for (var i = 0; i < n; i++) {
    $.ajax({
        method: "POST",
        url: './something.jsp',
        data : i,
        success: function(data) {
        ...
        }
     });
}

The 'for' statement is executing for some time and while is executing I cannot execute another ajax call.

What is the best practice for something like that and what can I do to execute another ajax call while my 'for' statement is executing?

Upvotes: 0

Views: 87

Answers (1)

William Humphreys
William Humphreys

Reputation: 1404

What I think you are asking is something a long the lines of multi-threading which Javascript doesnt have.

I.e.

StartNewThread(AjaxLoop)

mainThread:DoMoreStuffEvenIfAjaxLoopIsntComplete()

The nearest I think you can get to this though I havnt used it myself is with Web Workers http://www.w3schools.com/html/html5_webworkers.asp though this is really for newer browsers.

Upvotes: 1

Related Questions