必需的字符串参数“graphName”不存在

时间:2016-09-15 14:08:05

标签: javascript http

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”,则接受请求。

1 个答案:

答案 0 :(得分:1)

请求标头中的content type是您发送的内容。您没有发送Excel文件,而是请求excel文件。

当您发送"application/x-www-form-urlencoded"内容类型标头时,您告诉服务器必须在网址(this is the standard way)中读取您的参数。