Hey guys, I have come unstuck... cost...
I started using Ajax yesterday and have been pleasantly surprised by how easy to use it is...
What Ive done is build a crude instant messenger, which people need to log into... however, because of how I intend on using it... I want to be able to log people out when they close the browser (or a tab). So I thought I could use
window.onunload = removeLoggedIn();
Which will call a function which passes the user's username to a php script which deletes him out of the 'logged in' table... and thus he is not shown as online anymore...
So I tested my function by sticking an alert into it, and when I refresh the page - it fires... (It doesnt when you close the page, but maybe that isnt a problem as such).
Does anyone know why the function called upon onunload isn't passing the goods to my php script?
function removeLoggedIn(){
var http;
http=GetXmlHttpObject(); //create a valid xmlhttprequest
//get username, password to apss to php script
var userName = document.forms["loginForm"]["whoisit"].value;
var pword = document.forms["loginForm"]["pword"].value;
//php script details
var url = "logout.php";
var params = "uname=" + userName + "&pword=" + pword;
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(params);
}