views:

344

answers:

2

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

+1  A: 
Tomalak
+1  A: 

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.

ck
I suppose the requests have been cached. You can try adding a Pragma: no-cache header to the response to prevent browser side caching entirely without having to change all your code.
Tomalak
In any case: Preventing browser-caching must be looked at from several angles. A single "Pragma: no-cache" is not sufficient for all situations, I suggest you look up some more info to make sure all browsers understand what you want.
Tomalak