Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your <code>setTimeout</code> 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.</p> <p>So you're currently calling your recursion function a lot more frequently than you think you are. That's your first problem.</p> <p>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 <code>Loop</code> 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.</p> <p>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 <em>think</em> 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:</p> <pre><code>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 &lt; array.length) { renderChildData(array, index); } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload