我正在尝试从XMLHttpRequest ajax调用的onstateready中的responseText。目前我所有的退出我的responseText是“对象事件”我通过String()运行它,现在当我在它上面做一个typeof时,它返回字符串。我的控制台标题显示了所需内容的响应,但我的responseText没有得到它。我做错了什么?
我应该注意这不涉及jquery,保持原生。
function getPatterns() {
var url = document.URL;
var httpRequest;
if(window.XMLHttpRequest) { // modern browsers
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
httpRequest.onreadystatechange = function(responseText){
responseText = String(responseText);
console.log('responseText: '+ typeof responseText); // returns "string"
console.log('responseText: '+ responseText); // returns "object event"
// process the server response
};
httpRequest.open('GET', url+'&showpatterns=true');
httpRequest.send();
}