title: JQuery load() inside for loop
body: <p>I'm trying to write a Greasemonkey script where different pages are loaded with <code>.load()</code> using a for loop and store some of their informations in <code>localStorage</code>.
  My Problem: because <code>.load()</code> is asynchronous it doesn't work well. My script just stores the Last value I am trying to store. I think that is because i use the <code>var i</code> inside the callback function, and when the callback function is fired <code>i</code> has already another value.</p>
  
  <pre><code>for (var i = 0; i &lt; plantsDiv.length; i++)
  {
     objectid = plantsDiv[i].getAttribute('objectid');    
     $("#wrap").load("index.php?objectid="+ objectid,function(){
        //[...] what is happening
        window.localStorage.setItem(objectid,value);
     });
  }
  </code></pre>
  
  <p>When i insert <code>alert("foo")</code> between the callback function and the end of the for loop everything works, because the <code>.load</code> function is loaded, while i am clicking "ok" in the alert window.
  Is there any way to let the for loop wait until the whole <code>.load</code> is executed?</p>
  
  <p>Thanks for your help, and sorry for my Bad english :)</p>