2013-03-25 83 views
0

我需要在jquery移動應用程序(在桌面和移動設備上運行)中顯示文件列表。主要來自桌面,我需要從列表中下載一個文件。我有一個簡單的href如下:php下載文件

<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盒子上的瀏覽器上進行測試。

我在這裏錯過了什麼?

+0

'X-要求 - 由於:??XMLHttpRequest'難道不是一個簡單的鏈接 – 2013-03-25 17:45:59

+0

@ÁlvaroG.Vicario是啊,這讓我爲難,也。這是一個簡單的鏈接,也許jquerymobile正在接管所有的鏈接,我會嘗試禁用ajax。 – mlewis54 2013-03-25 17:48:26

+0

是的,我可能是錯的,但我不認爲你可以用AJAX下載文件。 – 2013-03-25 17:49:58

回答

0

答案相對簡單。 Jquery mobile使所有鏈接成爲Ajax請求(我已經遺忘了)。解決的辦法是加上「相對=」外部」的鏈接,使之成爲非Ajax鏈接爲:

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

由於阿爾瓦羅G.維卡里奧指着我在正確的方向

0

你還可以添加jQuet移動在此之前sceipt正確的,這對我的作品

<script> 
$(document).bind("mobileinit", function(){ 
    $.mobile.ajaxEnabled = false; 
}); 
</script>