为什么我onbeforeunload现在不运行时,它以前?或AJAX未能在第二个相同的命令?
-
05-09-2019 - |
题
此从此如下上问题
此的是强>工作:
<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问题...
解决方案
添加
&date=DateTime.now.Ticks.ToString()
似乎已经固定它。我不认为IE7喜欢它,当同样的AJAX电话打进来,和以前没有被“解决”(页面设置在AJAX调用返回前)。
由于所有所提供的帮助。
其他提示
有关调试的手段,我们尝试:
alert(url);
xmlhttp.open("GET",url,true);
这得到预期的结果:
UnlockQuery.ashx?QueryID=319&UserID=11648
现在,我们可以检查一下服务器通过说:
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4) alert(this.status + ": " + this.StatusText);
};
编辑:
事实证明,浏览器高速缓存是为意想不到的结果的原因。我建议禁止通过适当的HTTP报头(Pragma
,Cache-Control
,Expires
)。
不隶属于 StackOverflow