title: Casperjs, how to only proceed after receiving response from an ajax call
body: <p>I want casperjs to make an ajax call but wait for the result from my server.  This might take up to 3 minutes, but I can tell from looking at the results of running my script, casper.then function times out and just keeps going after exactly 30 seconds.  I've tried putting casper.options.waitTimeout = 180000 /* 3 minutes */; in my code, which does work, and I've tried using this block of code, which seems to wait 3 minutes every single time regardless of the result of my api call.  </p>
  
  <p>I also know that the evaluate function returns only a boolean every time no matter what, and this won't work as I need the api call data that is returned in the rest of my script.  How can I get this function to wait for 3 minutes?  And there is a lot going on behind the scenes, so yes, I need to wait this long. </p>
  
  <pre><code>var casper = require('casper').create();
  
  casper.start('mysite.html', function() {
  });
  
  casper.then(function() {
    result = getSomethingFromMyServerViaAjax( theId );
  });
  </code></pre>
  
  <p>This is the alternate method that I've tried that seems to always wait 3 minutes regardless or speed of the ajax call coming back.</p>
  
  <pre><code>casper.waitFor(function check() {
      return this.evaluate(function() {
          return result = getSomethingFromMyServerViaAjax( theId ) /* this takes up to 3 minutes */;
      });
  }, function then() {
     casper.log("Doing something after the ajax call...", "info");
     this.die("Stopping here for now", "error");
  }, 180000 );
  </code></pre>
  
  <p>I have tested my ajax call elsewhere and it works, as long as the response comes back in under 30 seconds, but if it doesn't casper just skips that block and keeps going every time.</p>