• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

XMLHttpRequest readyState undefined

BigDH01

Golden Member
<code>

function getXHTTP()
{
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
{
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
request_type = new XMLHttpRequest();
}
return request_type;
}




function login()
{
var http=getXHTTP();
var sURL="mypage.php";
http.open("POST", sURL, true);
http.onreadystatechange = getHttpRes;
var params = "username=" + encodeURI(document.getElementById('username').value) + "&password=" + encodeURI(document.getElementById('password').value);
http.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send(params);
}

function getHttpRes()
{
try{
alert(http.readyState);
if(http.readyState == 4)
{
var res = http.responseText;
alert(res);
/*
if(res)
{
document.getElementById('form-login').innerHTML="Login Success";
}
else
{
document.getElementById('login-fail').innerHTML="Login failure";
}*/
}
}catch(e){alert(e.value);}
}

</script>

</code>

I know I need to cleanup the browser type function, but for whatever reason I cannot get a value for readyState. The exception is always "undefined" and I always get it 4 times. I've tried this many different ways and I'm pulling my hair out. I can get readyState if I use GET. Using FF 3.5.6 and kubuntu 9.10. Any suggestions.
 
Looks like "http" is out of scope by the time you get to getHttpRes. Have you tried making it global?
 
Back
Top