This is a migrated thread and some comments may be shown as answers.

call ajaxRequest in pageUnLoad

6 Answers 147 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Pranav Dagaonkar
Top achievements
Rank 1
Pranav Dagaonkar asked on 26 Sep 2008, 08:51 PM
I try to make an ajax call (RadAjaxManager.ajaxRequest()) in pageUnLoad event handler. My goal is to save some data on the page before the page gets unloaded either by clicking an out-going url or by closing the browser window. However, I found after calling ajaxRequest(), the page cannot be unloaded. In other words, if I click a link, the new page will never get loaded. The following is the function I called in pageUnload(). Has anyone done something like this before? Any solutions? Thanks in advance.

 function SaveOnExit()  
            {                                 
                var ajaxManager = $find("<%= ram.ClientID %>");               
                ajaxManager.ajaxRequest();       
                
            }         

6 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 29 Sep 2008, 11:24 AM
Hi Pranav,

The question set forth has been addressed in the support ticket that you opened on the matter. To avoid duplicate posts, we can continue our communication there.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mostafa Anoosheh
Top achievements
Rank 1
answered on 06 Oct 2008, 01:35 PM
Hi,
Please let me know if you find any solution to solve this issue?

Best regards
Mostafa Anoosheh
0
Yavor
Telerik team
answered on 07 Oct 2008, 07:55 AM
Hello Mostafa,

Attached to this message, is a small application, which was furnished as a possible approach in this setup.
I hope it helps.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Pranav Dagaonkar
Top achievements
Rank 1
answered on 07 Nov 2008, 02:21 AM

I'm still having problem with reliably calling ajaxRequest() during page unload. Sometimes the call could get through and the other time it couldn’t (especailly with IE6 SP3). Is there a way that I can make a synchronous ajax call? Therefore, I can make sure the call is completed before the page gets unload.

Here is my code, I tried to call SaveOnExit() inside PageUnload(), Unload() and BeforeUnload(). But none of them are as reliably as I'd like. I event added some delay, but it still doesn't help much. It seems to me if I could make a synchronous ajax call so the page won't get unloaded until the response is coming back is the only way.

function SaveOnExit()
{
try{
var ajaxManager = $find("<%= ram.ClientID %>");
ajaxManager.ajaxRequest();
}
catch(e){
alert(e);
}
}

0
Yavor
Telerik team
answered on 07 Nov 2008, 08:17 AM
Hello Pranav,

Another option in this case would be to use a RadWindow, and use the onclose client side handler, to handle this setup.

All the best,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
HHalim
Top achievements
Rank 2
answered on 10 Nov 2008, 08:10 PM
I like to add that calling ajax requests within unload event may used up the internet connection within IE.

IE7 has 2 maximum live connections, when an ajax calls is interrupted, IE does not know how to close the connection, this results in a hang after 2 ajax calls within unload event. It is a serious issue that Firefox doesn't have. User has to either wait until the connection times out or force IE to close.

The only reliable solution is synchronous call within unload event.

Summary of the issue from MS support:
"It looks like IE will not send new requests to the same domain when the hang happens. What I can guess so far is, IE somehow doesn't know the connection should be closed if a user manually interrupts the AJAX request by closing the tab. By default, as you may know, IE only allows two subsequent connections to one domain. I've contacted our development team for a confirmation about this issue. They may need some time to come to a final conclusion. I'll follow up and update here. "

Here are links that discusses the issue:
http://bytes.com/forum/thread643080.html (contains a demo page that demonstrate the issue)
http://www.eggheadcafe.com/software/aspnet/33118270/ajax-and-ie-crash.aspx (Microsoft support replying to a user with the issue)

I hope this helps.
Tags
Ajax
Asked by
Pranav Dagaonkar
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Mostafa Anoosheh
Top achievements
Rank 1
Pranav Dagaonkar
Top achievements
Rank 1
HHalim
Top achievements
Rank 2
Share this question
or