Prøv en ajax-anmodning. Afhængigt af dit php-script skal du bruge $.post
eller $.get
jQuery:
<script language="javascript" type="text/javascript">
var username = null;
function GetUsername(usernameff){
username = usernameff;
}
window.onbeforeunload = function(){
if (username != null){
$.post('scripts/RemoveUserOnDisconnect.php', {username: username}, function(){
//successful ajax request
}).error(function(){
alert('error... ohh no!');
});
}
}
</script>
EDIT:
Dit php-script skal referere til $_POST
array, hvis du bruger min kode ovenfor.
<?php
$username = $_POST['username'];
mysql_connect("mysql.mysql.com", "username", "password");
mysql_select_db("my_db");
mysql_query("DELETE FROM my_table WHERE username = '$username'");
?>