为什么我的onbeforeunload现在不在以前运行?(Why is my onbeforeunload not running now when it was before? Or AJAX fa

系统教程 行业动态 更新时间:2024-06-14 16:57:18
为什么我的onbeforeunload现在不在以前运行?(Why is my onbeforeunload not running now when it was before? Or AJAX failing on second identical command?)

接下来是这个问题

这工作:

<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&amp;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问题....

This follows on from this question

This was working:

<body onbeforeunload= "ajaxRequest('UnlockQuery.ashx?QueryID=266&UserID=11631');">

This was created using the following in the aspx page:

<body onbeforeunload= "ajaxRequest('UnlockQuery.ashx?QueryID=<%= Session["QueryId"] %>& UserID=<%= Session["UserID"] %>')">

This is not working:

<body id="uxBodyTag" onbeforeunload= "ajaxRequest('UnlockQuery.ashx?QueryID=266&amp;UserID=11631');">

This is created using:

uxBodyTag.Attributes["onbeforeunload"] += "ajaxRequest('UnlockQuery.ashx?QueryID=" + queryId.ToString() + "&UserID=" + Session["UserID"].ToString() + "');";

The code being called is this:

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); } }

EDIT:

It appears to only fail when subsequent calls are made to the same unlock. I think this may be an AJAX issue....

最满意答案

添加

&date=DateTime.now.Ticks.ToString()

似乎已经修复它。 我不认为当相同的AJAX调用进来并且前一个没有被“解析”(该页面在AJAX调用返回之前被放置)时,IE7喜欢它。

感谢所有提供的帮助。

Adding

&date=DateTime.now.Ticks.ToString()

seems to have fixed it. I don't think IE7 likes it when the same AJAX call comes in and the previous hasn't been "resolved" (the page is disposed before the AJAX call returns).

Thanks to all that provided help.

更多推荐

本文发布于:2023-04-12 20:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/40db8dbe034deaedb3b55320298da9f1.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AJAX   running   onbeforeunload   command   identical

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!