954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

jQuery 'beforeunload' event running only once

Hello, i'm making a web site as a college project, this site features html,php,javascript,ajax,jquery and mysql. I'm almost done with the website... in the website i have a game, the players can create a 'lobby' and others players joins them, so, when a lobby is created an entry in the database is created, but if a player leaves the page without closing the lobby manually , the lobby has to be deleted through a unload event, here is my problem:

In my game window, i included this script:

$(window).bind('beforeunload', function() {
	$.ajax({
		url: "removelobby.php"
	});
});


As you can see i have only a 'beforeunload' event that makes a call to the file 'removelobby.php' which removes the lobby from the database with the info saved in the session variable, my problem is that this event seems to run only once, so if i create a lobby and quit, it gets deleted, but if i do it again, it doesn't get deleted.

How can i solvee this problem?
Thanks for your time.
Regards

AurosGamma
Newbie Poster
11 posts since Jun 2011
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: