自动检查如果声明php

时间:2015-05-22 12:38:27

标签: php

我如何在系统的索引页面中每秒查看 $ enjaz_youm

<?
if($enjaz_youm == 80) {
   echo "<script>";
   echo "alert('This is an alert from JavaScript!');";
   echo "</script>";
} 
?>

由于

1 个答案:

答案 0 :(得分:2)

你可以试试这个。

<?php
if ($_POST['action']=='enjaz_youm') {
    //do your checks here
    if ($enjaz_youm==80) echo '1';  
die();
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function()
{
    var refreshId = setInterval( function() 
    {

        var request = $.ajax({
                url: "<?=$_SERVER['PHP_SELF']?>",
                type: "POST",
                data: {action : 'enjaz_youm'},
                dataType: "html"
            });
            request.done(function(msg) {
                if (msg=='1') {
                    alert("This is an alert from JavaScript!");
                }
            });

    }, 1000);
});
</script>
</head>
<body>
</body>
</html>