0

I am in asp.net mvc paradigm. On one of my views, I have two fields Start Number and End Number. User is allowed to enter numeric values in these fields and when he clicks on submit button I have to loop from startNumber to endNumber and send an ajax requests for each iteration of the loop.

I have a scenario when the difference between start number and end number may range to 100's, so I am planning to send ajax requests in batch of 3 or 5. e.g I will send three requests and wait for them to complete and after that, I need to send next three until the loop is completed. I don't know how to target this problem.

halfer
  • 19,824
  • 17
  • 99
  • 186
Muhammad Adeel Zahid
  • 17,474
  • 14
  • 90
  • 155

2 Answers2

2

Instead of hammering your server with multiple AJAX request I'd recommend you send a single AJAX request containing all the necessary information. This will be more efficient rather than sending multiple requests with smaller payload.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Yes, In ordinary circumstances it is desireable to bundle ajax requests but in this case if I send all the necessary data in one or even 2 or 3 requests they might time out or at best user will have to wait more than a minute or two to see the response. – Muhammad Adeel Zahid Feb 20 '13 at 16:49
0

Create batch of 3 or 4 requests, and use below sample code which detect AJAX requests comepletes or not.

$( ".log" ).ajaxStop(function() {
  $(this).text( "Triggered ajaxStop handler." );
});

After comeleting all request,call another batch.

Khalid
  • 194
  • 4