jquery long-poll没有显示任何内容

时间:2013-08-09 19:07:46

标签: jquery long-polling

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

更新1:

的index.php

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

getDbData.php

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

原始代码:

的index.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
?>

getDbData.php

<?php
  $response = array();

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

我无法弄清楚我在哪里出错...

0 个答案:

没有答案