0

我需要在 jquery 移动应用程序(在桌面和移动设备上运行)中显示文件列表。主要从桌面我需要从列表中下载一个文件。我有一个简单的href如下:

<a href="download.php?file=test.txt">test.txt<a>

问题是当用户单击链接时,会显示文件的实际内容。我希望用户能够在本地保存文件。我相信我正确设置了标题。这是标头的 Firebug 转储:

Response Headers
Accept-Ranges   bytes
Cache-Control   public, must-revalidate, post-check=0, pre-check=0
Connection  Keep-Alive
Content-Disposition attachment; filename="test.txt"
Content-Length  95
Content-Type    application/octet-stream
Date    Mon, 25 Mar 2013 17:35:26 GMT
Expires -1
Keep-Alive  timeout=5, max=99
Pragma  public
Server  Apache/2.2.24 (Unix) mod_ssl/2.2.24 OpenSSL/1.0.0-fips
Request Headers
Accept  text/html, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cookie  PHPSESSID=bbf2549f793aed8565b44d532a3088dc; path=%2F; fileDownload=true
Host    192.168.1.225
Referer http://192.168.1.225/
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0
X-Requested-With    XMLHttpRequest

我正在通过 Windows 机器上的浏览器进行测试。

我在这里想念什么?

4

2 回答 2

0

答案比较简单。Jquery mobile 使所有链接成为 Ajax 请求(我忘记了)。解决方案是在链接中添加“rel="external”,使其成为非 ajax 链接,如下所示:

<a href="download.php?file=test.txt" rel="external">test.txt<a>

感谢 Alvaro G. Vicario 为我指明了正确的方向。

于 2013-03-25T18:15:04.637 回答
0

你也可以在 jQuet Mobile 之前添加这个 sceipt,它对我有用。

<script>
 $(document).bind("mobileinit", function(){
     $.mobile.ajaxEnabled = false;
 }); 
</script>
于 2013-09-24T21:56:14.290 回答