我试图让这个函数工作,它会请求参数,url
然后将 responseText 发送到callback
它是一个函数。
似乎它只能到达readyState 1
(感谢 Firebug 命令)。
这里是:
function Request(url, callback){
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else{
return false;
}
httpRequest.onreadystatechange = function(){
console.log(httpRequest.readyState);
if (httpRequest.readyState == 4) {
callback(httpRequest.responseText);
}
};
console.log(httpRequest, url);
httpRequest.open('GET', url, true);
httpRequest.send(null);
}