简体   繁体   中英

Php file download through ajax request

I am trying to download file through ajax request. I have below code in my php file to dowload

$filedata="File data here"
header("Content-type: application/octet-stream");
header("Content-Disposition:attachment; filename=report.txt");
header('Content-Transfer-Encoding: binary');
header("Pragma: public");
header("Expires: 0");
echo $filedata;

It giving me ajax response but not providing file download dialog box. Is any solution? Thanks in advance.

I think ajax is blocking the request.

Since its ajax that reads from the server it might not trigger the file save dialog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM