Reputation: 705
I am developing a module in Javascript, that in some strange cases, will launch multiple AJAX call to a web service in a range of Ips. For example:
var _requests = [],
_found = false;
for( var i = 1; (i < 255 && !_found); i++ ){
_requests.push( $.ajax({
url: "http://192.168.1." + i + "/service?action=example",
type: "GET",
success: _callback
}) );
}
var _callback = function( data, status, petitionInfo ) {
_found = true;
var _requestsToCancel = _requests.length;
while( _requestsToCancel-- ){
_requests[_requestsToCancel].abort();
}
};
In terms of performance, is it necessary (convenient), cancel every AJAX petition? Or it is irrelevant? When one ip responses, no other ip will do it. Putting a low timeout would be better for performance?
Upvotes: 3
Views: 463
Reputation: 3663
As you have already started the requests, each server will receive a request.
I'm assuming however that only one will respond and the others will time out. In which case I would recomend cancelling the other requests to save resources on the client.
Upvotes: 3