title: sending data to php and download file
body: <p>I need to send data to php file and download it.</p>
  
  <p>My script is working correctly when I call it directly, but when I send data with AJAX it doesn't download at all.</p>
  
  <p>My question would be: How to send data to php file and download file automatically but of course stay on the same page?</p>
  
  <p>Part of the code that is working when called directly...</p>
  
  <p><strong>PHP file</strong></p>
  
  <pre><code>header('Content-Description: File Transfer'); 
  header("Content-type: application/ms-word");
  header("Content-Disposition: attachment;Filename=ponuda.doc");
  
  $productsArr = json_decode($_POST['object']);
  $html = "&lt;tr&gt;";
  foreach($productsArr as $product)
  {
      //something
  }
  ....
  echo $html;
  </code></pre>
  
  <p><strong>AJAX call:</strong></p>
  
  <pre><code>$.ajax({
            type: "POST",
            url: "test_download.php",
            data: { object:productsJSON },
            cache: false
          });
  </code></pre>