我认为问题在于,您试图将文件结果加载到downloadmsg中,但这不起作用,因为.load()只将结果加载为html…而不是二进制数据或其他编码。
一种可能有效的方法是在HTML中创建隐藏的iframe,如下所示:
然后,将iframe的attr设置为querystring:
$("#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 ");
希望这有帮助!