I have a for loop inside which I am making a Ajax call which gives some response
for (var i in my_array)
{
ajax_call()
}
I am firing multiple Ajax request sometimes the Ajax response is not in order of Ajax request. I want to get the response in order same as request.
Is there any way to achieve this without adding any delay to application ?
Instead of a loop you could use a recursive function:
and then trigger:
This way it’s guaranteed that responses will arrive in the same order as requests simply because no other request is made before the first completes.
This being said, sending multiple AJAX requests like this is not a good idea. You should limit network connections as much as possible. It’s better to send one big AJAX request containing all the array data instead of multiple smaller AJAX requests for each element of your array.