I mean the onreadystatechange, not "onRequestChange"
Ok. I have a script that's intended to let a user login with his username and then get a list of all the users (and other things too, but I'll eliminate them for clarity.
Here's how it works.
Code:
//This first function just creates the object.
function createRequest() {
var newrequest;
try{
newrequest = new XMLHttpRequest();
} catch (e){
try{
newrequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
newrequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("You browser pro\'lly don\'t support AJAX, get the newest version of Firefox");
return false;
}
}
}
return newrequest;
}
//This next function is one I use as a multipurpose request sending thing.
function sendRequest(action)
{
switch (action) {
case "login":
var destination = "login.php";
var parameters = "username=" + username + "&action=login";
var handlereturn = new handleLogin();
break;
}
var request = createRequest();
request.onreadystatechange = handlereturn();
request.open("POST", desination, true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", parameters.length);
request.setRequestHeader("Connection", "close");
request.send(parameters);
}
function handleLogin() {
if (request.readyState == 4) {
switch (request.responseText) {
case "Logged In":
//Log In Successful
username = document.getElementById('username').value;
break;
case "Already Logged":
alert ("You or somebody else with that username is already logged in.");
break;
}
}
}
The problem is whenever I get to the handleLogin function, I get the error
"request is not defined".
I've tried making it global, and passing it as an argument but nothing seems to work. What am I doing wrong?
Thanks for your time!