waxical
waxical

Reputation: 3896

AJAX request for system operation holds up page rest of AJAX calls

I have a bunch of AJAX requests, the first is a

$.post("go.php", { url: pastedURL, key: offskey, mo: 'inward', id: exID});

This request, in go.php includes a system command, which despite nohup and & at the end, doesn't stop whirling on Firebug - waiting for response.

Unfortunately, the next AJAX request

$.post("requestor.php", { request: 'getProgress', key: offskey}, function(data) { console.log(data.response); }, "json");

Doesn't run, it whirls round in firebug (i'm guessing until go.php has finished) - it overloads everything eventually (this is on a timer to check every few seconds).

So I guess the question is, is there an AJAX method which simply throws data and walks away, instead of waiting for response... or someway I can perform another request whilst the other is waiting.

Hope someone knows what I mean.

Upvotes: 0

Views: 193

Answers (3)

Dave Methvin
Dave Methvin

Reputation: 1468

There are a limited number of connections used by the browser. The number varies by browser, but for older ones like IE7 it can be as little as 2 connections per server. Once you fill them with pending requests you have to wait for those to complete before you can make any additional requests to that server.

(this is on a timer to check every few seconds)

It sounds like you may be making additional requestor.php requests using setTimeout or setInterval before the previous ones have finished? If so, don't do that. Use a full $.ajax (perhaps with a timeout as well) and in the success/error callback only then make another request.

Upvotes: 0

waxical
waxical

Reputation: 3896

Turns out the PHP request on the other end would need this in order to proceed with waiting:-

"> /dev/null 2>/dev/null &"

source

Upvotes: 1

devdRew
devdRew

Reputation: 4571

Check for async: false, as parameter for $.ajax() method in jQuery.

You need it to be set async: true.

Upvotes: 1

Related Questions