0

这段代码有错误吗? 这里的例子

我尝试制作相同的示例,但效果不佳

如果有任何机构可以通过发送教程或任何帮助来帮助我,我想从数据库发出实时通知

注意:我使用 wamp 服务器在 localhost 上工作

HTML

索引.php

<!doctype html>
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script>
            var timestamp = null;
    function waitForMsg () {
        $.ajax({
            type: "GET",
            url: "getData.php?timestamp="+timestamp,
            async: true,
            cache : false,
            success : function (data){
                var json = eval('(' + data + ')');
                if (json['msg'] != "") {
                    alert(json['msg']);
                }

                timestamp = json['timestamp'];
                setTimeOut("waitForMsg()" , 1000);
            },
            erorr : function  (XMLHttpRequest,textStatus, erorrThrown) {
                alert("erorr :" + textStatus + "(" + erorrThrown + ")");
                setTimeOut("waitForMsg()", 15000);
            }

        });
    }

    $(document).ready(function(){
        waitForMsg();
    });
</script>
</head>
<body>

</body>
</html>

PHP

获取数据.php

<?php 
$filename = dirname(__FLIE__)."/data.txt";
$lastmodif = isset($_GET['timestamp']) ? $_GET['timestamp'] : 0;
$currentmodif = filemtime($filename);

while($currentmodif <= $lastmodif){
    usleep(10000);
    clearstatcache();
    $currentmodif = filemtime($filename);
}

$response = array();
$response['msg'] = file_get_contents($filename);
$response['timestamp'] = currentmodif();
echo json_encode($response);

?>

4

1 回答 1

0
$response['timestamp'] = currentmodif();

应该

$response['timestamp'] = $currentmodif;

currentmodif 是一个变量而不是一个函数。

于 2013-07-14T20:44:31.047 回答