javascript ajax调用MVC控制器返回EmptyResult [英] javascript ajax call to MVC controller to return EmptyResult
本文介绍了javascript ajax调用MVC控制器返回EmptyResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这看起来应该很容易,但经过几个小时尝试不同的组合我没有取得任何成功。
我想做的就是从javascript调用以下MVC控制器EndSession:
This seems like it should be easy to do, but after hours of trying different combinations I haven't had any success.
All I want to do is call the following MVC controller EndSession from javascript:
[HttpGet]
public virtual ActionResult EndSession()
{
Session.Abandon();
return new EmptyResult();
}
这是js:
Here is the js:
function SessionTimeOutHandler() {
$.ajax({
url: "/Home/EndSession",
type: 'Get',
success: function (result) {
if (result.success) {
}
}
});
}
我在Session.Abondon()上设置了一个断点,但从未达到过。非常感谢任何帮助/建议。
I've set a break point on Session.Abondon(), and it is never reached. Any help/suggestions are greatly appreciated.
推荐答案
.ajax({
url: / Home / EndSession,
类型:' 获取',
成功:功能(结果){
if (result.success){
}
}
});
}
.ajax({ url: "/Home/EndSession", type: 'Get', success: function (result) { if (result.success) { } } }); }
我在Session.Abondon()上设置了一个断点,但从未达到过。非常感谢任何帮助/建议。
I've set a break point on Session.Abondon(), and it is never reached. Any help/suggestions are greatly appreciated.
您是否检查过SessionTimeOutHandler()方法是否被调用?因为当我添加一个按钮如下所示,如果我点击按钮,它对我来说工作正常!
Did you check whether the SessionTimeOutHandler() method is getting called at all? because when I added a button as below it's working fine for me if I click the button!
<input type="submit" onclick="javascript:SessionTimeOutHandler();" value="Log Off" />
这篇关于javascript ajax调用MVC控制器返回EmptyResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文