这是从这个问题开始的
这是有效的:
<body onbeforeunload=
"ajaxRequest('UnlockQuery.ashx?QueryID=266&UserID=11631');">
这是在 aspx 页面中使用以下内容创建的:
<body onbeforeunload=
"ajaxRequest('UnlockQuery.ashx?QueryID=<%= Session["QueryId"] %>&
UserID=<%= Session["UserID"] %>')">
这不起作用:
<body id="uxBodyTag" onbeforeunload=
"ajaxRequest('UnlockQuery.ashx?QueryID=266&UserID=11631');">
这是使用以下方法创建的:
uxBodyTag.Attributes["onbeforeunload"] +=
"ajaxRequest('UnlockQuery.ashx?QueryID=" +
queryId.ToString() + "&UserID=" + Session["UserID"].ToString() + "');";
被调用的代码是这样的:
function ajaxRequest(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
{ // code for all new browsers
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{ // code for IE5 and IE6
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=null;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
}
编辑:
它似乎仅在对同一解锁进行后续调用时才会失败。我认为这可能是一个 AJAX 问题....