var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("excel download");
}
};
xhttp.open("POST", "exportGraphExcel", true);
xhttp.setRequestHeader("Content-type", "application/msexcel");
xhttp.send('graphName=graphakki');
它在浏览器中提供400状态。 如果Content-type更改为“application / x-www-form-urlencoded”,则接受请求。
答案 0 :(得分:1)
请求标头中的content type是您发送的内容。您没有发送Excel文件,而是请求excel文件。
当您发送"application/x-www-form-urlencoded"
内容类型标头时,您告诉服务器必须在网址(this is the standard way)中读取您的参数。