function exitXMLHttpChange() { if(exitxmlHttp.readyState==4) { if(exitxmlHttp.status==200) { var hs=exitxmlHttp.responseText;
if(hs!=1) alert("退出失败!"); else alert("ccc"); } } } </script> </head> <body style="font-size:10pt" onbeforeunload="exitW()"> Ajax:using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OleDb;public partial class ExitAjax : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { OleDbConnection upCon = new OleDbConnection(OleDbTest.con_str); upCon.Open(); OleDbCommand upCmd = new OleDbCommand("update LTUser set Status='lixian' where ZhangHao='" + Request.QueryString["zhanghao"] + "'", upCon); int hs = upCmd.ExecuteNonQuery(); upCmd.Dispose(); upCon.Dispose(); Response.Write(hs); Response.End(); } }
31.点插关闭页面时的js:
<head>
<script type="text/javascript">
function show()
{
alert("test");
} </script>
</head>
<body onunload ="javascrip:show();">
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
</form>
</body>
<script>
function window.onbeforeunload(){ }
}
</script>
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
var exitxmlHttp;
function exitCreateXMLHttpRequest()
{
if(window.ActiveXObject)
exitxmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
if(window.XMLHttpRequest)
exitxmlHttp=new XMLHttpRequest();
}
function exitW()
{
exitCreateXMLHttpRequest();
exitxmlHttp.open("get",encodeURI("ExitAjax.aspx?zhanghao="+document.getElementById("HiddenField1").value+"&date="+new Date().getTime()),true);
exitxmlHttp.onreadystatechange=exitXMLHttpChange;
exitxmlHttp.send(null);
}
function exitXMLHttpChange()
{
if(exitxmlHttp.readyState==4)
{
if(exitxmlHttp.status==200)
{
var hs=exitxmlHttp.responseText;
if(hs!=1)
alert("退出失败!");
else
alert("ccc");
}
}
}
</script>
</head>
<body style="font-size:10pt" onbeforeunload="exitW()">
Ajax:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;public partial class ExitAjax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection upCon = new OleDbConnection(OleDbTest.con_str);
upCon.Open(); OleDbCommand upCmd = new OleDbCommand("update LTUser set Status='lixian' where ZhangHao='" + Request.QueryString["zhanghao"] + "'", upCon);
int hs = upCmd.ExecuteNonQuery(); upCmd.Dispose();
upCon.Dispose();
Response.Write(hs);
Response.End();
}
}
或者用这种方式试试
那是传到一个aspx页了,先在aspx页设置一个断点,看值传过来没有,值没传过来,就是ajax代码有问题
我设断点跟踪了一下,正好要执行到OleDbConnection upCon = new OleDbConnection(OleDbTest.con_str);
这句话时,它就退出了。??
FOR=window EVENT=onunload 是什么意思?
一个一个判断
1.先判断
Request.QueryString["zhanghao"] 是否为空,在page_load里面加上
string value= (Request.QueryString["zhanghao"] != null) ? Request.QueryString["zhanghao"].ToString() : "";退出报什么错?
我怀疑onbeforeunload和onunload这两个事件是不是有时间限制啊??
讨论:Asp.Net/C#/Asp/Access/Sql Server;css,html,js,ajax;网站经营;爱情;工作;人生;
你把执行的代码放到全局页面试试。
愚见啊,不知道对不