[英]read data returned from jquery .post
I have a page that I want redirected to the login page if a user is inactive for 1/2 hour. 如果用户在1/2小时内处于非活动状态,则我有一个页面要重定向到登录页面。 I am new to jQuery and it has taken me awhile to get this far.
我是jQuery的新手,花了我一段时间才走到这一步。 So basically the user logs in they are redirected to the home page.
因此,基本上用户登录后,他们将被重定向到主页。 I have jQuery running on the home page that posts to the check_time.php page every 10 seconds.
我在主页上运行的jQuery每10秒发布到check_time.php页面。 if they have been inactive for more than a 1/2 hour, then session is destroyed and they get redirected to the login page.
如果闲置时间超过1/2小时,则会话将被破坏,并将其重定向到登录页面。 I have everything working except checking the value of the "data" that is returned from the check_time.php page.
除了检查从check_time.php页面返回的“数据”的值之外,我一切正常。
here is the code on the home page. 这是主页上的代码。
ini_set('session.gc_maxlifetime',1800);
ini_set('session.gc_probability',1);
ini_set('session.gc_divisor',1);
session_start();
if($_SESSION['admin_login'] != $password){
header('Location: index.php');
exit();
}
if(isset($_SESSION['last_activity']) && (time()-$_SESSION['last_activity'] >1800)){
// last request was more than 30 minates ago
session_destroy(); // destroy session data in storage
session_unset(); // unset $_SESSION variable for the runtime
header('Location: index.php');
exit();
}
$_SESSION['last_activity'] = time(); // update last activity time stamp
?>
<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function timedCount(){
$.ajax({
type: 'POST',
url: "check_time.php",
success: function(data){
if (data == "LOGOUT") {
window.location = 'index.php';
}
}
});
setTimeout("timedCount()",10000);
};
</script>
this is the code on the check_time.php 这是check_time.php上的代码
<?php
session_start();
if (isset($_SESSION['last_activity'])){
if(time() - $_SESSION['last_activity'] > 1800){
session_unset();
session_destroy();
echo "LOGOUT";
}
}else{
echo "LOGOUT";
}
?>
I asked this same question last week I wanted to post my latest code so I stated a new question. 上周我问了同样的问题,我想发布自己的最新代码,所以我提出了一个新问题。 I really greatly appreciate your help!!!!!
我真的非常感谢您的帮助!
try : 尝试:
if (jQuery.trim(data) == "LOGOUT")
{
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.