我使用以下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