title: Running one thing after another in jquery
body: <p>I have this code snippet from something i am developing</p>
  
  <pre><code>&lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(function(){
          $("#Submit").click(function(){
          var Count = document.frmOne.count.value
          for (i=1;i&lt;=Count;i++)
          {
              $.ajax({
                  url:"process.php",
                  type:"get",
                  data:$("form").serialize(),
                  success:function(response){
                      var obj = jQuery.parseJSON( response );
                      var success = obj.success;
                      var actionsNumber = obj.number;
                      $("#result").html('There have been  '+actionsNumber+'  loops completed');    
  
  
                  }
              })
          }
                  $.ajax({
                       url:"done.php",
                       type:"get",
                        })
          })
      })
  &lt;/script&gt;
  </code></pre>
  
  <p>and basically I need to have the whole for loop complete then have it run "done.php". But currently it seems to run done.php after about 2 loops in the for loop. </p>
  
  <p>So lets see if i can explain this better. I have this whole js script run after someone clicks a submit button.  I have it run process.php for a user inputted amount of times, then i want it to run done.php after it finishes the for loop.  But it is currently running process.php about twice, then done.php, then continues with process.php.   </p>
  
  <p>How can i fix this?</p>
  
  <p>Now i have tried this and it is not working still, any help please</p>
  
  <pre><code>&lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(function(){
          $("#Submit").click(function(){
          var Count = document.frmOne.count.value
          var b = 0
          for (i=1;i&lt;=Count;i++)
          {
              $.ajax({
                  url:"process.php",
                  type:"get",
                  data:$("form").serialize(),
                  success:function(response){
                      var obj = jQuery.parseJSON( response );
                      var success = obj.success;
                      var actionsNumber = obj.number;
                      $("#result").html('There have been  '+actionsNumber+'  loops completed');   
                      b++;
  
  
                  }
  
              })
      if(Count == b)
              {
                  $.ajax({
                      url:"done.php",
                      type:"get",
  
                        })
                        var b = 0
              }
          }
  
  
  
          })
      })
  &lt;/script&gt;
  </code></pre>