How does jQuery.post() deal with Content-Disposition: attachment?

◇◆丶佛笑我妖孽 提交于 2019-12-02 06:39:48

It's simply not possible. AJAX requests never cause user prompts.

However, you can simply make the request return e.g. JSON or plaintext containing the URL and then use location.href = ...; to redirect to it; this will result in the prompt you are looking for.

If the request always results in a file download, you could also consider using a regular form and not using AJAX at all; if the response triggers a download dialog the previous page will remain in the browser window anyway.

Hieu Van Mach

Why you do not link straight to print.php

and call php output to the browser using this code

$fp = fopen("php://output", 'w');
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=test.doc");
$fp = fopen("php://output", 'w');
fwrite($fp,"your content here");
fclose($fp);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!