日期:2014-05-17  浏览次数:20502 次

关于JS定时器判断cookie是否超时的问题(在线等,急求)
主要是实现这样一个功能,页面打开后,如果一段时间没有操作,就清楚Cookie然后提示他登陆超时然后自动刷新到登陆页面
下面贴下代码,我写了个JS,在每个模板页里面都引用了,但是只有首页弹出登陆超时,其他都不会,不知道为什么。
$(document).ready(function () {
    setInterval("Timer()", 62000);
})

function Timer() {
    var strUrl = "Customer/TimeOver?time="+Math.random;
    $.ajax({
        type: "POST",
        url: strUrl,
        success: function (data) {
            if (data.msg == "true") {
                alert("登陆超时,请重新登陆");
                window.parent.location.href = "/Account/LogOn";
            }
        }
    });
}



下面是后台代码
public ActionResult TimeOver()
        {
            if (LoginOut(User.Identity.Name))
            {
                FormsAuthentication.SignOut();
                return JsonGet(new { success = true, msg = "true" });
            }
            else
            {
                return JsonGet(new { success = false, msg = "false" });
            }
        }


请教各位大神,在线等,急求
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js读取cookie测试</title>
<link href="css/08nzfh-style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.STYLE1 {color: #FF0000}
-->
</style>
</head>

<body>

<div class="personality">
<script type="text/javascript">
//<![CDATA[
function   setCookie(name,value) 

    var   Days   =   30;   //此   cookie   将被保存   30   天 
    var   exp     =   new   Date();         //new   Date(&nb