Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  177] [ 6]  / answers: 1 / hits: 6387  / 10 Years ago, fri, april 25, 2014, 12:00:00

I have about 100 ajax requests that I fire at the same time, I thought browsers only allowed a few requests simultaneously, so the rest would be added to a queue.



The problem however is that jquery/javascript seems to use the timeout value from the time the requests were created via jquery, not from the time the requests were actually executed by the browser. So I get a bunch of timeouts. Is it possible to have the timeout start counting from the time the request is actually going to the URI location, instead of the time it is added by jquery?


More From » jquery

 Answers
2

Here is a kind of queue system. Starts by calling the ajax function N times, and then after each success, calls ajax function again. There is also a check in the success callback to see if all the assets have been loaded...



demo fiddle



$(document).ready(function(e) {
$(form[ajax=true]).submit(function(e) {

e.preventDefault();

var form_url = $(this).attr(action);
var form_method = $(this).attr(method).toUpperCase();

$(#loadingimg).show();

var started = 1, done = 0;
function ajax(){
$.ajax({
url: form_url,
type: form_method,
data: html=started +(started++),
cache: false,
success: function(returnhtml){
done++;
$(#result).html(returnhtml);
$(#loadingimg).hide();
if(started <= 100){
ajax();
} else if (done == 100) {
alert(all done!);
}

}
});
}
// how many concurrent calls?
for(i=0;i<10;i++){
ajax();
}
});

});

[#45762] Thursday, April 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryans

Total Points: 514
Total Questions: 92
Total Answers: 121

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
;