title: Chaining ajax requests with jQuery's deferred
body: <p>I have a web app which must call the server multiple times. So far, I had a long nested callback chain; but I would like to use jQuery's <code>when</code>,<code>then</code> etc. functionality. However, I can't seem to get stuff running again after using a <code>then</code>.</p>
  
  <pre><code>$
  .when ($.get('pages/run-tool.html'))
  .then (function (args)
  {
      // This works fine
      alert(args);
      $('#content').replaceWith (args);
      $('#progress-bar').progressbar ({value: 0});
  })
  .then ($.get('pages/test.html'))
  .done (function(args)
  {
      // This prints the same as the last call
      alert (args);
  });
  </code></pre>
  
  <p>What am I doing wrong? I guess its some scoping issue, as I can see the second <code>get</code> call being executed. Using two different <code>args</code> variables does not help as the argument passed to the done function is still the first <code>get</code> request.</p>