I know I just posted one on Friday, but another issue with the same program....
I can't seem to get a response from my PHP UNLESS I add an alert(http.readyState) to my code.
<script language="Javascript" type="text/Javascript">
var http;
function getXmlHttpObject()
{
try
{
var xmlHttp = new XMLHttpRequest();
}
catch (e1)
{
try
{
var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e2)
{
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function login()
{
http=getXmlHttpObject();
var sURL="login.php";
http.open("POST", sURL, true);
http.onreadystatechange = function()
{
if(http.readyState == 4 || http.readyState == "complete")
{
if(http.status == 200)
{
alert(http.responseText);
var res = http.responseText;
alert(res);
if(res == "false")
alert("false");
}
}
}
var params = "username=" + encodeURI(document.getElementById('username').value) + "&password=" + encodeURI(document.getElementById('password').value) + "&ajax=true";
//http.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http.send(params);
}
</script>
The above will do nothing. If I add alert(http.readyState) in my onreadystatechange function, I will see it progress from 1 to 4, an alert will display showing me the expected response, and then I'll get another "1" and another alert with my response. Without the alert(http.readyState), I get nothing. Any ideas?
I can't seem to get a response from my PHP UNLESS I add an alert(http.readyState) to my code.
<script language="Javascript" type="text/Javascript">
var http;
function getXmlHttpObject()
{
try
{
var xmlHttp = new XMLHttpRequest();
}
catch (e1)
{
try
{
var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e2)
{
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function login()
{
http=getXmlHttpObject();
var sURL="login.php";
http.open("POST", sURL, true);
http.onreadystatechange = function()
{
if(http.readyState == 4 || http.readyState == "complete")
{
if(http.status == 200)
{
alert(http.responseText);
var res = http.responseText;
alert(res);
if(res == "false")
alert("false");
}
}
}
var params = "username=" + encodeURI(document.getElementById('username').value) + "&password=" + encodeURI(document.getElementById('password').value) + "&ajax=true";
//http.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http.send(params);
}
</script>
The above will do nothing. If I add alert(http.readyState) in my onreadystatechange function, I will see it progress from 1 to 4, an alert will display showing me the expected response, and then I'll get another "1" and another alert with my response. Without the alert(http.readyState), I get nothing. Any ideas?