Search code examples
apachejqueryjquery-mobile

jQuery Ajax abort and new request in quick succession


I have a mobile app, which makes a

JqXHR = $.ajax({
    url: 'url',
    data: null,
    async: true,
    cache: false,
    dataType: 'json',
    type: 'GET',
    crossDomain: true,
    timeout: 63000,
    success: function(data, textStatus, jqXHR) {},
    error: function(jqXHR, textStatus, errorThrown) {}
});

request. It waits for 63 seconds (the PHP backend CAN run for ~62 seconds) for user interaction at the other end. Now, if in the meanwhile I decide to abort this request, then i call JqXHR.abort(). In the error handler I already handle/differentiate between real errors and aborts, that works. Right after the abort, I want to send an other API call to the server to tie the loose ends and make sure my cancel request is logged.

And there is the problem. Even tho I abort() the first request, the PHP script is still running on the server, which wouldn't be a problem if it also executed the second request, which would make it to stop and die(). But it is not happening. The second request is not happening until the first finishes.

Any ideas?

jQuery 1.8.2, jQuery Mobile 1.2.0, PhoneGap 2.0.0 and 2.1.0, Apache 2, Linux, PHP 5.3


Solution

  • It seems I ran into the good old PHP sessions vs. AJAX requests issue. Actually my boss found out about this issue by googling some expressions i never thought of. I am using Zend framework in the back-end, and it automatically starts a session namespace, so in my API controller's preDispatch() method I had to put in a @session_write_close(); line, and as if by magic, it works like a charm.

    Thanks Arun for your quick reply, it is most appretiated.

    So, in short: If you use Zend Framework or session_autostart or other means of starting sessions, they won't fly with parallel AJAX requests.