Marcel Colomb
Marcel Colomb

Reputation: 622

Async ajax requests aren't really async (JQuery and Zend)

I've got a stack of ajax request:

$("someTable tr").each(function() {

    // send the data.
    var scriptURL = "/module/action/data/" + $(this).find(".data").html() + "/";

    document.cyonVars.xhrPool[count] = $.ajax({
    type: "GET",
    url: scriptURL,
    queue: "autocomplete",
    cancelExisting: true,
    dataType: 'json',

    success: function(data){

       // do something

        }

    }
    });
    count++;
})

While these requests are running the user can press a button. This triggers another ajax request. Something like that:

var scriptURL = "/module/anotheraction/" +
data) + "/";

$.ajax({
    type: "GET",
    url: scriptURL,
    queue: "autocomplete",
    cancelExisting: true,
    dataType: 'json',

    success: function(data){
    // Do another thing
    }
});

The requests from the first action responding asynchrone as I wish. When a user triggers the second request that one waits till the other requests are finished. But the second request should be proceed earlier. I already worked with session_write_close() didn't changed anything. Thanks for helping.

Upvotes: 0

Views: 414

Answers (2)

Marcel Colomb
Marcel Colomb

Reputation: 622

The problem was Zend_Session::Start();

I had to avoid using Zend_Session while proceeding async requests

Upvotes: 0

fazo
fazo

Reputation: 1827

i'm not so sure, that it should be processed futher. browsers have limits on connections to the same server and if it takes long for a request to reply your app might stop on few or more requests. just think, that async requests are shoot asynchronously (code after ajax request continues to execute), but requests are executed in sequence.

Upvotes: 1

Related Questions