title: send two ajax requests one after another
body: <p>im working on an HTML5 project that uses multiple canvases,
  after the user finishes drawing using the canvas i  save them as images to the server.
  this is what i have:</p>
  
  <pre><code>        function saveViaAJAX()
          {
        $("#dvloader").show();
         document.getElementById("search-result").innerHTML="saving first image...";
  
          var saveCanvasFront = document.getElementById("collage-front");
          var canvasDataFront = saveCanvasFront.toDataURL("image/png");
          var postDataFront = "canvasData="+canvasDataFront;
          var debugConsole= document.getElementById("search-result");
  
          var saveCanvasBack = document.getElementById("collage-back");
          var canvasDataBack = saveCanvasBack.toDataURL("image/png");
          var postDataBack = "canvasData="+canvasDataBack;
  
          var ajax = new XMLHttpRequest();
          ajax.open("POST",'index.php?option=com_canvas&amp;format=raw&amp;task=savecanvas',true);
          ajax.setRequestHeader('Content-Type', 'canvas/upload');
  
          var ajax2 = new XMLHttpRequest();
          ajax2.open("POST",'index.php?option=com_canvas&amp;format=raw&amp;task=savecanvas',true);
          ajax2.setRequestHeader('Content-Type', 'canvas/upload');    
  
  
  
         ajax.onreadystatechange=function()
          {
              if (ajax.readyState == 4)
                  {
                document.getElementById("search-result").innerHTML="saving second image..";
              ajax2.send(postDataBack);
               }
          }
  
         ajax2.onreadystatechange=function()
         {
          if (ajax2.readyState == 4)
           {
  
          document.getElementById("search-result").innerHTML="canvases saved successfully";
          setTimeout('top.location.href="index.php"', 4000)
              $("#dvloader").hide();
  
           }
         }    
  
         ajax.send(postDataFront);
          }
  </code></pre>
  
  <p>im sure there is a more elegant way to achieve this. i just want to make sure both requests are successful.this is why im calling them serially, one after the other.
  is this correct ?
  Thanks </p>