AnsweredAssumed Answered

Ajax requests in a for-loop? (Blog Dashlet)

Question asked by tbarg on Mar 20, 2012
Latest reply on Mar 21, 2012 by erikwinlof
I'm currently modifying the Blog Dashlet to be a user dashlet that displays the blog posts from all sites of a member.
I succeeded at this (the displaying part, I don't need the "create post" functionality) , but stumbled upon a few odds.

If I bundle Ajax Requests in a for-loop, the loop terminates before the requests are completely processed.

loadPosts: function SiteBlog_loadPosts(sites)
    for(var i = 0; i<sites.length; i++){        
            url: Alfresco.constants.PROXY_URI + "api/blog/site/" + sites[i] + "/blog/posts?pageSize=25",
               fn: this.onPostsLoaded_Collector,
               scope: this
               fn: this.onPostsLoadFailed,
               scope: this
            scope: this,
            noReloadOnAuthFailure: true
"sites" is an array of site names, the loop is the first step to collect posts from all the sites in "sites". I got the overall code working with a few detours,
but the for-loop terminates, before the successcallback methods terminate (or run, for that matter). I don't know much about javascript, but how is that even possible? How can a loop terminate before the code within it? Is there a proper way to ensure that the loop does not terminate before the ajax requests?