Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6694155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:04:09+00:00 2026-05-26T06:04:09+00:00

I have a for loop inside which I am making a Ajax call which

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:04:09+00:00Added an answer on May 26, 2026 at 6:04 am

    Instead of a loop you could use a recursive function:

    function sendAjax(myArray, index) {
        $.ajax({
            url: '/someurl',
            type: 'POST',
            data: { id: myArray[index].id },
            success: function(result) {
                // TODO: do something with the result of the AJAX call
    
                if (index < myArray.length) {
                    // proceed with the next call if we still have
                    // elements in the array to process
                    sendAjax(myArray, index++);
                }
            }
        });
    }
    

    and then trigger:

    sendAjax(my_array, 0);
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following loop inside an function init(); which is executed onload, I
I have a for loop, and inside it a variable is assigned with var.
I have the following query which is inside a loop and is breaking SELECT
I have a recursive function which contains some drawing code inside. I was advised
I have this loop which gives seg. fault. s->c = malloc(width * height *
I have php code which executes a loop, inside which it generates the following:
I have a for loop. Inside that loop I want to fill up an
i want to have a foreach loop where the initial array is changed inside
I have a Parallel.ForEach loop running an intensive operation inside the body. The operation
Suppose, I have a if statement inside a for loop: for( ; ; )

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.