title: jQuery ajax: Want to sequence the code process
body: <p>I am getting data from php file through ajax. Based on the data I need to do some processing. I have put a few alerts in my code, and from that I realize that the code outside the ajax is being executed before ajax gets the data. I want the code to be done after the data is received from php file.</p>
  
  <p>Code:</p>
  
  <pre><code>$(function () {
      var originalData=""; 
      $.ajax({                                      
        url: 'data.php',                    
        data: "",                        
        dataType: 'text',               
        success: function(data)          
        {
          originalData=data;
          alert("originalData 1 "+ originalData);  
        }
      });
  
      alert("originalData 2 "+ originalData);  
      ...
        Processing code
      ...
  });
  </code></pre>
  
  <p>The sequence of alerts is:</p>
  
  <p>First : "originalData 2" </p>
  
  <p>Second : "originalData 1" </p>
  
  <p>One option is that I include the <code>Processing code</code> inside the <code>success</code> function, but I cannot do it because later I want to put a logic such that I can have a buffer of <code>data</code> (atleast 4-5 stack deep) because I want user to get new <code>data</code> instantly after processing code for current <code>data</code>, rather than wait for the <code>data</code> to be retrieved through php.</p>