通过ajax调用php下载文件
onclick
function csv(){ ajaxRequest = ajax();//ajax() is function that has all the XML HTTP Requests postdata = "data=" + document.getElementById("id").value; ajaxRequest.onreadystatechange = function(){ var ajaxDisplay = document.getElementById('ajaxDiv'); if(ajaxRequest.readyState == 4 && ajaxRequest.status==200){ ajaxDisplay.innerHTML = ajaxRequest.responseText; } } ajaxRequest.open("POST","csv.php",false); ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); ajaxRequest.send(postdata);}
$fileName = 'file.csv';$downloadFileName = 'newfile.csv';if (file_exists($fileName)) { header('Content-Description: File Transfer'); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename='.$downloadFileName); ob_clean(); flush(); readfile($fileName); exit;}echo "done";
大话西游666
catspeake