Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>$.each()</code> is synchronous. It's just a loop that calls a function directly, nothing fancy or mysterious about it. In your code, <code>$.each()</code> will call <code>loadNewFacebookPage()</code>, that function will run to completion, and then <code>$.each()</code> will move on to the next element.</p> <p>But is that what you're really asking about? <code>loadNewFacebookPage()</code> sounds like it's probably an asynchronous function. If it is, are you saying that you want to wait until the asynchronous activity has completed before moving on to the next loop iteration? The <code>$.each()</code> loop won't do that. Nor would an ordinary <code>for</code> loop. Instead, <code>loadNewFacebookPage()</code> would need to provide a completion callback, and that callback would advance a "loop" variable.</p> <p>If you can tell more about <code>loadNewFacebookPage()</code>&mdash;in particular whether it has a completion callback or one could be added&mdash;then it would be more clear what to do.</p> <p>For example, suppose <code>loadNewFacebookPage()</code> takes a second argument which is a completion callback function. Then you could write code like this:</p> <pre><code>$.getJSON( url, { uid: user }, function( rsp ) { var i = 0; next(); function next() { if( i &lt; rsp.length ) { var favorite_pageid = rsp[i++]; loadNewFacebookPage( favorite_pageid, next ); } } }); </code></pre> <p>Suppose that <code>loadNewFacebookPage()</code> were using the <code>$.ajax()</code> function to load the data. (It probably isn't doing that, is it? But this will serve to illustrate.) Then you might do something like:</p> <pre><code>function loadNewFacebookPage( id, done ) { $.ajax({ url: makeUrlFromId( id ), success: function( data ) { doStuffWithData( data ); done(); } }); } </code></pre> <p>I'm omitting a bunch of stuff here like error handling just to illustrate an example.</p>
    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.
 

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