简体   繁体   English

jQuery PHP Ajax检查用户登录show modal

[英]jQuery PHP Ajax Check User Logged in show modal

I have jQuery PHP Ajax to check user logged in or not. 我有jQuery PHP Ajax来检查用户是否登录。

JS JS

jQuery(document).ready(function()
{
setInterval(function()
{
    jQuery.ajax({
    url: 'chkLoggedin.php',
    type: 'POST',
    success:function(response)
    {
        if(response == "sessionExpired")
        {
            bootbox.dialog(
            {
                message: "Please login to continue",
                title: "Not logged in",
                buttons:
                {
                    success:
                    {
                        label: "Log in",
                        className: "btn-success",
                        callback: function()
                        {
                            $('.bootbox').modal('hide');
                        }
                    }
                }
            });
            return false;
        }
    }
});
}, 5000);
});

PHP PHP

require("config/db.php");
session_start();
include("config/session.php");

if(empty($session))
{
    echo "sessionExpired";
}

I tried the above code is working, but after logout the modal show multipe until I refresh the page. 我试过上面的代码是有效的,但是在注销模态后显示multipe直到我刷新页面。 I just want the modal show 1 time. 我只想要一次模态秀。

使用setTimeOut函数而不是setInterval

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

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