0

这是从这个问题开始的

有效的:

<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 问题....

4

2 回答 2

1

对于调试的手段,我们尝试了:

alert(url);
xmlhttp.open("GET",url,true);

这给出了预期的结果:

解锁Query.ashx?QueryID=319&UserID=11648

现在我们可以通过以下方式检查服务器必须说的内容:

xmlhttp.onreadystatechange = function() { 
  if (this.readyState == 4) alert(this.status + ": " + this.StatusText); 
};

编辑:

事实证明,浏览器缓存是导致意外结果的原因。我建议禁止通过适当的 HTTP 标头 ( Pragma, Cache-Control, Expires) 缓存 AJAX 页面。

于 2009-02-19T11:10:45.817 回答
1

添加

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

似乎已经修复了它。我不认为 IE7 喜欢当相同的 AJAX 调用进入并且前一个尚未“解决”(页面在 AJAX 调用返回之前被处理)时。

感谢所有提供帮助的人。

于 2009-02-19T11:21:06.167 回答