如何在Asp.net MVC中检测页面卸载? [英] How to detect the page unload in Asp.net MVC?

查看:53
本文介绍了如何在Asp.net MVC中检测页面卸载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Asp.net MVC中检测页面卸载?

How to detect the page unload in Asp.net MVC?

推荐答案

有很多方法可以检测到该页面已被加载,下面是其中一个:


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


(窗口).unload(function(){

// post - > controller action


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


.ajax

({

类型:'POST',

url:'/ ControllerName / ActionName',

data:{ParameterCollection},

dataType:'html',

错误:功能(xhr,状态,错误)

{

//显示相应的消息

alert('error');

},

成功:function(){

//显示相应的消息

alert('success');

}

});

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


这篇关于如何在Asp.net MVC中检测页面卸载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆