我使用以下ajax調用將一些數據發送到PHP頁面,該頁面生成一個excel文件。如果我自己運行PHP頁面,假冒的數據已經歸屬於一個數組,它會下載文件,但如果我嘗試通過ajax按鈕運行php頁面,則無法下載。我不確定這個問題是什麼,但是當php嘗試發回文件時,我得到500 Internal Server Error
。請看下圖:如何使用AJAX請求返回文件
請求報頭:
POST /XLS.php HTTP/1.1
Host: 127.0.0.1
Connection: keep-alive
Content-Length: 15
Pragma: no-cache
Cache-Control: no-cache
Accept: */*
Origin: http://127.0.0.1
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
Content-Type: text/plain;charset=UTF-8
Referer: http://127.0.0.1/multiLine.php
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,fr-FR;q=0.6,fr;q=0.4
Cookie: PHPSESSID=rd44cluc503datf36616b9e5b5; popupPartNumber=null
響應頭:
HTTP/1.0 500 Internal Server Error
Date: Fri, 13 Mar 2015 18:21:55 GMT
Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15
X-Powered-By: PHP/5.5.15
Content-disposition: attachment; filename="multiLine report 03.13.15 - .xlsx"
Content-Transfer-Encoding: binary
Cache-Control: must-revalidate
Pragma: public
Content-Length: 0
Connection: close
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
我使用了Ajax是:
$.ajax({
url: "XLS.php",
type: "post",
data: {xl: xl},
}); //closes ajax call
,我已經經歷了約7個不同的contenttype:
選項來查看是否有其中一個產生了差異,但他們都沒有。
我該如何取回這個文件?
這是一個內部服務器錯誤。看看你的服務器端代碼和你的錯誤日誌。您無法知道是什麼原因導致客戶端發生內部服務器錯誤,這不是客戶端錯誤。 – Quentin 2015-03-13 19:45:03