title: PHP-Ajax force download
body: <p>I am trying to allow users to save progress by saving an array of data to a file. I know I can force a php download by changing the headers, but I am calling the php script with an ajax call that needs a response to re-enable a button.The reason I neeed to disable the button in the first place is jquery has to gather ALOT of data to send to the script and it takes a couple of seconds to do. I have posted my code below which just saves a local file. Ideally I would just like a "save to" dialog and let ajax know it wen ok.</p>
  
  <p>So could I force a download and still echo back the json data response? </p>
  
  <p>Thank you once again,
  Todd</p>
  
  <pre><code>require_once('../FirePHPCore/fb.php');
  session_start();
  
  /* Initialize an ajax pessimistic response object. */
  $ResponseData = array
  (
      'Success' =&gt; false,
      'Message' =&gt; 'There was an error saving your chart right now. Please try again later.'
  );
  
  // assemble the final array to save to disk 
  $finalArray                   = array();
  $finalArray['colorChart']     = $_POST['colorChart'];
  $finalArray['threadBrand']    = $_POST['threadBrand'];
  $finalArray['chartName']      = $_POST['chartName'];
  $finalArray['stitchChart']    = $_POST['stitchChart'];
  
  file_put_contents('array.txt', serialize($finalArray));
  
  $ResponseData['Success'] = true;
  $ResponseData['Message'] = 'Saved.';
  /* Output the response data in JSON. */
  echo json_encode($ResponseData);
  </code></pre>