0

出于某种原因,以下内容根本没有显示任何内容-知道我做错了什么吗?

更新 1:

索引.php

$(document).ready(function(){
  (function poll(){
    $.ajax({ url: \"getDbData.php\", success: function(data){
      document.write(data.timestamp);
    }, dataType: \"json\", complete: poll, timeout: 30000 });
  })();
});

获取数据库数据.php

$response = array();
$response['timestamp'] = time()+microtime();
echo json_encode($response);
sleep(1);

原始代码:

索引.php

<?php

echo "
<html>
<head>

<script src=\"jquery.min.js\" type=\"text/javascript\" charset=\"utf-8\"></script>

<script type=\"text/javascript\">
  $(document).ready(function(){
  (function poll(){
    $.ajax({ url: \"getDbData.php\", success: function(data){
      var json = eval('('+data+')');
      if json['timestamp'] != \"\" {
        document.write(json['timestamp']);
      }, dataType: \"json\", complete: poll, timeout: 30000 });
    })();
  });
</script>

</head>
<body>
</body>
</html>

"; //end of echo
?>

获取数据库数据.php

<?php
  $response = array();

  for ($testLoop=0; $testLoop < 100; $testLoop++) {
    $response['timestamp'] = time()+microtime();
    echo json_encode($response);
    sleep(1);
  }
?>

我只是不知道我要去哪里错了......

4

0 回答 0