XMLHttpRequest()有错误吗?为什么显示ReferenceError: xmlhttprequest is not defined啊?



```javascript
var url ="http://api.lfemcp.com/token/get";
//var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
var xhr =new XMLHttpRequest();
xhr.open('POST',url,true);
xhr.setRequestHeader("Content-type","application/x-wwww-form-urlencoded");
var obj ='appKey=2045486032334ec287e4698f11b9cd60&appSecret=2b363714a46a42a6aef660797a5f20ef&account=SDULIMS';
xhr.send(obj);
xhr.onreadystatechange = function(){
    if(xhr.readyState == 4 && xhr.status == 200) {
        var res=xhr.responseText;
        console.log(res);
    }
}


```

没问题呢你的代码,不会用的IE6吧?IE6需要用activexobject来创建,不支持XMLHttpRequest。有帮助麻烦点个采纳【本回答右上角】,谢谢~~有其他问题可以继续交流~

xhr.setRequestHeader("Content-type", "application/x-wwww-form-urlencoded");

==》这里多了个w,所以没有发送键值对,接口无法正常获取数据,去掉就可以正常请求了

xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
img

因为你用了require然而 并没有把这个包导入进来。

看代码没什么问题,xmlhttprequest 是第五行的问题,那就删掉试试

img