Lesson 33 AJAX readyState stuck at 1.
Hey I've figured out the problem is my readyState is stuck at 1 and not changing to 4 at the makeGetRequest stage.
here's the code I copied from the book
function makeGetRequest(url,callback){
var xhr = createXHR();
xhr.open("GET",url);
console.log(xhr.readyState //Returns 1
xhr.onreadystatechange=function (){
if(xhr.readyState ===4){
if ((xhr.status >=200 & xhr.status < 300) || xhr.status===304){
callback(xhr.responseText);
}else{
alert('something went wrong');
}//end else
}//end if
};//end function
a fix i've found is replacing xhr.onreadystatechange with xhr.onload any input would be appreciated thanks!
|