我希望jgrowl只在登录后弹出一次

时间:2017-10-17 06:13:05

标签: javascript php jquery html jgrowl

这是我的问题,我尝试使用jgrwol进行通知并完成。现在我希望登录后弹出一次通知。当我刷新页面或移动另一个菜单并返回到通知菜单时,它不应再弹出。

代码:

<script type="text/javascript">
    $(function() {
        $.jGrowl("<p class='upper'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> <?=$row['NTFY_TTL'];?></p><?=$row['NTFY_DESC'];?><br> <small>Posted <?=$row['BEG_DT'];?></small>", { 
             theme: 'test',
             position: 'top-right',
             life: 3000 
        });
    });
</script>

代码登录:

<?php
include "framework/database/connect.php";

$loginUserID=$_POST['userID'];
$password=$_POST['password'];
if(substr($password,-1)=="~"){
    $display="?DISP=ON";
    $password=substr($password,0,-1);
}
if(substr($password,-1)=="+"){
    $display="?DISP=TRIM";
    $password=substr($password,0,-1);
}
if($password!=''){
    $query="SELECT SEC_KEY,PRSN_NBR,PWD FROM CMP.PEOPLE PPL INNER JOIN CMP.POS_TYP POS ON PPL.POS_TYP=POS.POS_TYP WHERE PRSN_ID='".$loginUserID."' AND (PWD='".$password."' OR PWD='".hash('sha512',$password)."') AND TERM_DTE IS NULL";
    //echo $query;
    $result=mysql_query($query);
    $row=mysql_fetch_array($result);
    if(mysql_num_rows($result)==0){
        $warning="<font color='red'>Id or Pass is wrong.</font><br />";
    }else{
        $warning="<br/>";
        $_SESSION['userID']=$loginUserID;
        $_SESSION['personNBR']=$row['PRSN_NBR'];
        //Enforce hashing
        if($row['PWD']==$password){
            $query="UPDATE CMP.PEOPLE SET PWD='".hash('sha512',$password)."' WHERE PRSN_NBR=".$_SESSION['personNBR'];
            //echo $query;
            $result=mysql_query($query);
        }
        header('Location:index.php'.$display);
        exit;
    }
}elseif($_GET['COMMAND']=="LOGOUT"){
    unset($_SESSION['userID']);
    unset($_SESSION['personNBR']);
}elseif($_GET['COMMAND']=="LOCK"){
    $defServer=$OLTA;
    mysql_connect($defServer,"root","Pr0reliance");
    mysql_select_db("cmp");
    $query="UPDATE NST.PARAM_LOC SET TAX_LOCK=1";
    $result=mysql_query($query);
}elseif($_GET['COMMAND']=="UNLOCK"){
    $defServer=$OLTA;
    mysql_connect($defServer,"root","Pr0reliance");
    mysql_select_db("cmp");
    $query="UPDATE NST.PARAM_LOC SET TAX_LOCK=0";
    $result=mysql_query($query);
    $defServer=$OLTP;
}
?>

1 个答案:

答案 0 :(得分:0)

使用localstorage进行设置和获取值。 Check this fiddle ,当您在登录页面时清除本地存储,因此当您从登录页面返回菜单页面时它将再次显示。

$(function() {  
   if(!localStorage.getItem('growl')){
        $.jGrowl("<p class='upper'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> <?=$row['NTFY_TTL'];?></p><?=$row['NTFY_DESC'];?><br> <small>Posted <?=$row['BEG_DT'];?></small>", { 
             theme: 'test',
             position: 'top-right',
             life: 3000 
        });

                localStorage.setItem('growl', true);
   }

});

localstorage删除。

localStorage.removeItem('growl');