AurosGamma 0 Newbie Poster

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.