Hi, I would appreciate your opinion/advice on the following
Scenario
HTML has PDF file nick name, back end has URL for each nick.
The link URL is always download.php?what=%PDF_Nick% to ensure download for JS disabled clients.
For JS enabled clients I do JQuery AJAX call and rewrite link URL from download.php?what=%PDF_Nick% to http://mysite.com/requestedPFF.pdf to activate download from the client. I set "async: false" to allow AJAX get new url.
Problem
AJAX returns valid script rewriting JS url variable, but location.href runs again to the initial url, creating extra back end call
Do you think it's related to the bug ignoring "async: false," definition or it's mistake I've made and missed to catch?
Thank you in advance
HTML code
<a href="/download.php?what=PDF_A" onclick="javascript:download ('PDF_A')">Download</a>
JS code
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; }
Back end (download.php) code
$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"); }