Note that there are some explanatory texts on larger screens.

plurals
  1. POChrome error on downloading file via iframe
    primarykey
    data
    text
    <p>I'm submitting JSON data to a server. The server generates a PDF file and responds with the URL to that PDF file. I then make another request to the server to download the PDF file. To do the download, I create a hidden iframe and set the source the the PDF url. Note that I want the user's browser to stay on the same page and download in the background. More details about what I'm doing and the solution I went with can be found in <a href="https://stackoverflow.com/questions/3499597/javascript-jquery-to-download-file-via-post-with-json-data/3506018#3506018">this SO question</a>.</p> <p>Whenever I use this technique in Chrome, everything works fine. But looking at the chrome developer console, I see the error message <code>Failed to load resource</code>. <strong>Is there a way to do this differently so that I won't get these errors?</strong></p> <p>A very simple and working <a href="http://jsfiddle.net/94WvR/1/" rel="nofollow noreferrer">example of the problem in action</a> can be seen on jsfiddle. Just click the Download PDF button and look at your Chrome console.</p> <p>The code on that page looks like this:</p> <pre><code>$(document).ready( function() { var downloadFile = function(url){ var iframe = $("iframe#download"); if (!iframe.length) { iframe = $("&lt;iframe id='download' style='display:none;'/&gt;"); $("body").append(iframe); } iframe.attr("src", url); }; $("button").click(function() { downloadFile("http://www.education.gov.yk.ca/pdf/pdf-test.pdf"); }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload