title: Wait until ajax is done
body: <p>I have a code like this:</p>
  
  <pre><code>var links="";
  function upload(file){
     var fd = new FormData();
     fd.append("image", file); // Append the file 
     // Create the XHR (Cross-Domain XHR FTW!!!)
     var xhr = new XMLHttpRequest();
     xhr.open("POST", "http://someapi.com");
     xhr.onload = function() {
        // Big win!
        // The URL of the image is:         
          links += "[IMG]"+JSON.parse(xhr.responseText).upload.links.original+"[/IMG]\n";                 
          //showResult(JSON.parse(xhr.responseText).upload.link);
     }
     // Ok, I don't handle the errors. An exercice for the reader.
     // And now, we send the formdata
     xhr.send(fd);
  }
  function catchFiles(files){
      nfiles = files.length;
      //var links="";
      for(var i=0;i&lt;nfiles;i++){
          upload(files[i]);
      }                       
  }
  function showResult(links){     
      document.getElementById('div_result').innerText = links;                    
  }
  </code></pre>
  
  <p>What I want is how to wait until the catchFiles is done (upload done all file) after that, the showResult will be call.</p>
  
  <p>Any solution?</p>
  
  <p>Thanks</p>