我正在尝试捕捉浏览器窗口的关闭事件,所以我发现这个post对我来说似乎没问题,但我需要修改它只是为了调用php脚本.....我是jquery真的很新。
这是我在$(document).ready()
中的代码:
// main.php
<?php
// include some classes
?>
<html>
<head>
<!-- include jquery -->
<script>
...
var inFormOrLink;
$('a').live('click', function() { inFormOrLink = true; });
$('form').bind('submit', function() { inFormOrLink = true; });
$(window).bind("beforeunload", function() {
if(confirm("Do you really want to close?") || (inFormOrLink = true))
{
$().load('closing.php?val=value&closing=true');
} });
</script>
closing.php页面调用php函数来更新数据库中的行。它 不起作用....用户失去会话..并且行未更新。有没有办法在窗口关闭之前调用页面?..
// closing.php
public function update($int1, $string, $int2, $int3) // should take parameters from $_GET in url
{
$query = "UPDATE table SET valore = $int1 WHERE id = $int2 AND playerid='".mysql_real_escape_string($string)."' AND id_us = $int3";
$res = mysql_query($query) or die(mysql_error());
if(mysql_affected_rows() == 1){
return TRUE;
}
else
{
return FALSE;
}
}
第二个问题:如何将$ _GET值从main.php传递给closing.php? 感谢...