Multiple requests with ajax - Jquery

Asked

Viewed 151 times

0

I have a page containing 1 (one) to 50 requests. So I use a loop that makes the call.

By the speed of my internet, in a matter of 3 seconds I should upload all the requests. But it’s done one by one, then it takes minutes to finish.

How do I launch all these requests at once?

Note: The result can be given after the return of each, not in the whole.

for(var obj in value){
   $.ajax({
       method:"POST",
       url : "tracker/correios-xml.php",
       data : {cod_correios: e.dados.e_tracking_number, c_retorno : class_add},
       dataType : "json",
       error: function(request, status, erro){

       },
       success: function(e, status, request){

       }
   });
}
  • I believe it is not possible, since each request has its own values, I imagine that they should be done individually.

  • @dvd So, I add the ID(number) of the div and send and bring it back, then I know where to add each part, regardless of the position it is. I would like to send everything at once, from there according to that I was returning I played the values for the respective Ivs... but the way it is going, it goes one at a time... let’s say, does not load the last, because it still has the antipenúltima that did not return...

  • 1

    The ajax requests as you have in the question have no relation to each other. I see nothing there that makes them wait for each other.

  • @Sergio Understand, so it is normal to be slow like this... Because today checking, I realized that some rare carry in front of others. I was hoping by the speed of the Internet you could load them all at once. As it is slow, I ended up changing the system to load only when the element becomes visible, then avoid, I believe overload less the server, because in each sale I have to call a 5 different requests... ATT

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.