title: How are $.ajax callbacks handled on the stack? (Firefox vs Chrome vs ... )
body: <p>Good evening guys -</p>
  
  <p>I've noticed that different browsers seem to handle callbacks differently. </p>
  
  <p>As an example, Firefox seems to let an $.ajax.done({}) callback interrupt the current javascript instruction, but Chrome won't handle the $.ajax.done({}) callback until all current instructions finish. It's like Chrome sends the call to the end of an instruction <strong>queue</strong>, and Firefox adds it to the top of the instruction <strong>stack</strong>.</p>
  
  <p><em>(Bear in mind that this is probably entirely incorrect terminology - I really hope this is the right place to post this)</em></p>
  
  <p>Explicit Example that outlines my best guess:</p>
  
  <pre><code>function load_a_bunch_of_stuff()
      $.ajax({
          // ajax things here - e.g. load 10,000 whatevers from a server
  
      }).always(function() {
          ajaxStatus = "done!"
      });
  }
  
  function do_things_with_loaded_stuff() {
      // Loops as long as the status is "running" and the User is 
      // willing to retry:
      while (ajaxStatus === "running" &amp;&amp; 
          confirm("Waiting on ajax, try again?"));
  
      // Do some cool stuff after the $.ajax call finishes
  }
  
  // --
  // Main: (Assume do_things_with_loaded_stuff() is called before the 
  //   load_a_bunch_of_stuff() finishes)
  
  var ajaxStatus = "running";
  load_a_bunch_of_stuff();
  do_things_with_loaded_stuff();
  </code></pre>
  
  <p>-- My best guess --</p>
  
  <p>In this example - the loop will run until Firefox lets the .always({}) change the 'ajaxStatus' to "done!" (probably while the user tries to click on OK) and then we can carry on. </p>
  
  <p>However in Chrome, the .always({}) doesn't ever fire because (I'm guessing) the callback is executed <strong>after</strong> the current set of instructions finishes. In other words, since the .always({}) is added to the end of the instruction set (rather than in the next slot), it's stuck in the loop and never reaches the .always({}).</p>
  
  <p>This example is just something similar to an issue I've ran into recently while trying to develop between the two browsers. Does anyone know if this interpretation is true? </p>
  
  <p>Can anyone actually explain what's going on?</p>