怎样在关闭浏览器时更新数据库值?

来源:百度知道 编辑:UC知道 时间:2024/06/18 10:46:13
<html>
<script language="JavaScript">
<!--
var exit=true;
function ext()
{
if (exit)
window.open("exit.asp");}
//--></script>
<body onunload="ext()">
</body>
</html>

这是我找到的退弹代码,在关闭浏览器时会弹出一个exit.asp网页,我想问的是有没有办法在不弹出网页的情况下更新数据库里的数据???
表list
id____int型__1
up____int型__默认0

怎么要退出浏览器时将up的"0"改为"1"(id=1)

用xmlhttp就可以了
以下是全代码:
<html>
<script language="JavaScript">
<!--
var exit=true;
function ext()
{
if (exit)
var Str=1
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST", "out.asp?Name="+Str, false);
xmlhttp.send();
}
//--></script>
<body onunload="ext()">
</body>
</html>

out.asp
<!--#include file="conn.asp" --> //数据库连接文件
<%
ID=request("Name")
sql = "update [list] set up=1 where ID="&CInt(ID)
conn.Execute(sql)
%>

这个除非是用session_end事件,不然只能用那个。