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

  • SEARCH
  • Home
  • 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 936151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:16:02+00:00 2026-05-15T21:16:02+00:00

I have this recursion loop where inside the function I have atleast 2 ajax

  • 0

I have this recursion loop where inside the function I have atleast 2 ajax get/post, and the recursion happens after the first ajax get. my function structure is like this,

function Loop() {
    $.get(url, data, function(result) {
        for loop to render the result {
            // render the result here
        }
        for loop to get another data using the result {
            $.post(url, result.data, function(postResult) {
                // I don't know what it did here since 
                // I don't have an access to this post
            });
            // is there a way here that i will not proceed if the post is not done yet?
        }
        setTimeout("", 1000); // I wait for 1 second for the post to finish
        Loop(); // call the recursion
    }, "json");
}

can anyone tell me what’s wrong with this code? why do i get a warning from the computer that my script is causing the computer to run slowly. I know that this code is the one causing it, but I don’t know the work around.

I know inside the second loop inside the get is causing a lot of memory. Is there a way that it will not loop back if the ajax post is not finished?

  • 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-15T21:16:03+00:00Added an answer on May 15, 2026 at 9:16 pm

    Your setTimeout will not neatly pause the code for one second: it will just set a timer for an (empty, in your case) event to go off after a certain time. The rest of the script will continue to execute parallel to that.

    So you’re currently calling your recursion function a lot more frequently than you think you are. That’s your first problem.

    Your biggest problem, though, is that regardless of what you’re doign in the result of your post, that’s in another scope entirely, and you cannot break out of the Loop function from there. There is nothing in your code to break the recursion, so it is infinite, and very fast, and it sends off Ajax requests on top of that.

    You need to describe in more detail what you want to achieve, and perhaps somebody can show you how you should do it. The only thing that is certain is that you need to use callbacks. I’ve written an example but it’s making a lot of assumptions. It’s a lot of approximations of what I think you might want to achieve, but no doubt you’ll need to tweak this a bit to fit your needs. Hopefully it’ll give you an idea of the workflow you need to use:

    function Loop() {
        $.get(url, data, function(result) {
            for loop to render the result {
                // render the result here
            }
    
            // this is what you're looping over in your second loop
            var postQueue = result.someArray;
    
            renderChildData(postQueue, 0);
        }, "json");
    }
    
    function renderChildData(array, index) {
    
       // this is just one item in the loop
       var currentItem = array[index];
    
       $.post(url, currentItem, function(postResult) {
    
           // we have received the result for one item
           // render it, and proceed to fetch the next item in the list
    
           index++;
           if(index < array.length) {
              renderChildData(array, index);
           }
    
       });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a recursive query like this (note: this is just an example): var
I have a recursive model like this: public class Node { public int Id
I have a recursive data type like this: template<typename T> struct SomeType { std::map<T,
Imagine I have a recursive algebraic data type like this (Haskell syntax): data Expr
Let's say we have a simple recursion like. int x(int a){ if(a<10) x(a+1); else
This question is more a semantic-algorithmic-data-structure question than a F# syntactically question. I have
I have this function that I wrote that is abysmally slow since php does
I have a recursive function which contains some drawing code inside. I was advised
I have this code which iterates over a tree, doing a depth-first search. Every
If you have a recursive structure, say, child tables located inside td cells of

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.