Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery $.ajax "async: false" bug?
    primarykey
    data
    text
    <p>I would appreciate your opinion/advice on the following</p> <p><strong>Scenario</strong> </p> <p>HTML has PDF file nick name, back end has URL for each nick. </p> <p>The link URL is always download.php?what=%PDF_Nick% to ensure download for JS disabled clients. </p> <p>For JS enabled clients I do JQuery AJAX call and rewrite link URL from download.php?what=%PDF_Nick% to <a href="http://mysite.com/requestedPFF.pdf" rel="nofollow noreferrer">http://mysite.com/requestedPFF.pdf</a> to activate download from the client. I set "async: false" to allow AJAX get new url.</p> <p><strong>Problem</strong></p> <p>AJAX returns valid script rewriting JS url variable, but location.href runs again to the initial url, creating extra back end call</p> <p>Do you think it's related to the bug ignoring "async: false," definition or it's mistake I've made and missed to catch?</p> <p>Thank you in advance</p> <h1>HTML code</h1> <pre> &lt;a href="/download.php?what=PDF_A" onclick="javascript:download ('PDF_A')">Download&lt;/a> </pre> <h1>JS code</h1> <pre> function download ( what ) { var url = "download.php?what="+what; $.ajax({ type: "GET", url: "download.php?ajax=true", data: "what=" + what async: false, dataType: "script" }); // if AJAX got the download URL I expect actual download to start: location.href = url; } </pre> <h1>Back end (download.php) code</h1> <pre> $myPDF = array(); $myPDF["PDF_A"] = "PDF_A.pdf"; .... $url = "http://mysite.com/" . $myPDF["PDF_A"]; ... if ( $_GET["ajax"] === "true" ) { // overwrite JS url variable print('url = "'.$url.'";'); } else { header("Location: ". $url ); header("Connection: close"); } </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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