title: CasperJS: capturing JSON sent response to javascript onClick()
body: <p>In CasperJS, I am working with a site that has a button like this:</p>
  
  <pre><code>&lt;a id="showBills" 
     onclick="javascript:{showBills(); return false;}" 
     href="#"&gt;Show Bills&lt;/a&gt;
  </code></pre>
  
  <p>Clicking it generates an XMLHttpRequest POST message with a massive form full of magic numbers and state.  The server responds by sending a JSON data structure that I want to capture.</p>
  
  <p>In this case, I can't simply call <code>casper.getPageContent()</code> to get the JSON data, since it's interpreted by the client and incorporated into the DOM.  </p>
  
  <p>Nor can I call <code>casper.download(...)</code> since I can't manually reconstruct the form data required for the POST request.</p>
  
  <h3>the question</h3>
  
  <p>How can I 'intercept' the JSON data sent in response to an onClick()-backed click?</p>
  
  <h3>half an idea</h3>
  
  <p>There may be some way to subvert the showBills() method on the client, for example to send the JSON response as an ordinary page (rather than an XMLHttpRequest).  But that's just beyond my understanding of CasperJS, PhantomJS and HTTP protocols.</p>