Bakir Odeh
Bakir Odeh

Reputation: 23

Auto Check If statement php

How i can check $enjaz_youm every second in the index page for my system

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

Thanks

Upvotes: 0

Views: 222

Answers (1)

l0ckm4
l0ckm4

Reputation: 747

You can try this.

<?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>

Upvotes: 2

Related Questions