我认为问题在于您正在尝试将文件结果加载到#downloadmsg中,这将不起作用,因为.load()仅将结果加载为HTML
…而不是二进制数据或其他编码。
一种可行的方法是在HTML中创建隐藏的iframe,如下所示:
<iframe id="secretIframe" src="" ></iframe>
然后,将iframe的attr设置为您的查询字符串:
$("#secretIframe").attr("src","myphpscript.php?option1=apple&option2=orange");然后在设置源时使用PHP标头强制下载(这是我的一个使用八位字节流的脚本中的一个导出器标头集示例):
header("Pragma: public");header("Expires: 0");header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download");header("Content-Type: application/octet-stream");header("Content-Type: application/download");header("Content-Disposition: attachment;filename=data.xls ");header("Content-Transfer-Encoding: binary ");希望这可以帮助!



