I'm trying to get this function to work, which does a request for parameter url
then sends the responseText to callback
which is a function.
It seems that it only gets to readyState 1
(thanks to the Firebug commands).
Here it is:
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);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…