Click here to Skip to main content
15,887,987 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to detect the page unload in Asp.net MVC?
Posted

There are many approaches to detect that page has been loaded, below is one of them:

$(window).unload(function() {
//post - > controller action

$.ajax
({
type: 'POST',
url: '/ControllerName/ActionName',
data : { ParameterCollection },
dataType: 'html',
error: function (xhr, status, error)
{
//show appropriate message
alert('error');
},
success: function(){
//show appropriate message
alert('success');
}
});
});
 
Share this answer
 
With $(window).unload() you’d be able to confirm the results of the ajax call, like handle returned data on a call back function and I guess the page would have gone away by then.
If you need some sort of confirmation that the ajax call was successful, or to handle returned data, look for a way to do it before unload.

Use this,
JavaScript
window.onbeforeunload = function (e) {

}


-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900