简体   繁体   English

来自Javascript MVC的自动操作结果调用

[英]Automatic action result call from Javascript MVC

I am working on a website and I am wanting to redirect to Action Result called logout automatically in 20 second. 我正在一个网站上工作,我想在20秒内自动重定向到称为注销的操作结果。

This is what I have so far: 这是我到目前为止的内容:

setInterval(function redirectAction() {

    var url = '@Url.Action("Logout")';

}, 20000);

The timing system works. 计时系统正常工作。 I tired using alert and it alerts every 20 seconds. 我厌倦了使用警报,它每20秒发出一次警报。 BUT when it starts after page load, it starts with 20 second delay and then alerts which is important because I need user to be in one page for 20 seconds then logouts. 但是,当它在页面加载后启动时,它以20秒的延迟开始,然后发出警报,这很重要,因为我需要用户进入一页20秒钟然后注销。

Overall, what I'm trying to achieve is how to automatically call an action result from controller using javascript. 总的来说,我想要实现的是如何使用javascript从控制器中自动调用动作结果。 I've tried researching GET method and AJAX, but still haven't able to find a clear solution and nothing worked so far. 我曾尝试研究GET方法和AJAX,但仍无法找到明确的解决方案,到目前为止没有任何效果。

just do this : 只是这样做:

setInterval(function redirectAction() {

window.location.href ="your url you want to redirect to it"

//example
//window.location.href ="YourController/logout"

}, 20000);

also you can use setTimeout for delay like this : 您也可以使用setTimeout进行延迟,如下所示:

 setTimeout(function () {
       window.location.href = "YourController/logout"
    }, 2000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM