<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.
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.