Hello,
I’m using AJAX in a login form for user authentication. The Javascript code is shown below:
[CODE]function login_check(email, password){
var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
else
{
alert(“Your browser does not support XMLHTTP (which is required to use this site), or your security setting is too high. All modern browsers support XMLHTTP. Please upgrade your browser to a newer version or lower your security setting to use this site.”);
}
// define request response
var request_response;
xmlhttp.onreadystatechange=function()
{
try {
if(xmlhttp.readyState==4)
{
if(xmlhttp.status == 200) {
request_response=xmlhttp.responseText;
<do a bunch of stuff here>
}
else
{
alert(‘There was a problem with the XMLHTTP request.’);
}
}
}
catch ( e ) {
alert(‘Caught Exception: ‘ + e.description);
}
}
// send request to server
var url=”PHPscripts/login_check.php”;
var params=”email=”+email;
params=params+”&password=”+password;
xmlhttp.open(“POST”,url,true);
//Send the proper header information along with the request
xmlhttp.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”);
xmlhttp.setRequestHeader(“Content-length”, params.length);
xmlhttp.setRequestHeader(“Connection”, “close”);
xmlhttp.send(params);
}
As mentioned earlier, I get inconsistent behavior in IE (behavior is fine in Firefox). In IE, even for the same email and password (the only 2 arguments passed into the Javascript function above), I get one of three behaviors:
-sometimes login is succesful
-sometimes I get the ‘There was a problem with the XMLHTTP request.’ message shown in the code above (indicating that status != 200)
-and sometimes nothing happens when the login button is pressed.
Again, these inconsistencies in IE occur even between different trials of using the same login email and password. Does anyone know why this may occur, and how it could be fixed?
EDIT: Fogot to mention that I am using IE7