jquery定时功能不起作用

时间:2016-04-18 12:08:59

标签: javascript php jquery

我有一个javascript函数,应该每3秒为扑克网站的游戏页面调用一次。它只调用一次

继承人的PHP

if(isset($_GET['displayGame']))   //Check if submitted
{
  $thisPokergame = new pokerGame();
  $thisPokergame->read($_GET['gameid']);

  $thisPlayer->read($_GET['userid']);

  // $thisPokergame->State['currentUser'] = $thisPokergame->State['privatePlayerData'][$_GET['userid']];

  // unset($thisPokergame->State['privatePlayerData']);
  // $thisPokergame->State['players'].length();
  // $thisPokergame->State = array('1'=>'test');
  echo json_encode($thisPokergame->State);
  return;
}

这是javascript

function refreshGamepage()
{
  console.log("gameid:"+$("#gameid").val());
  console.log("userid:"+$("#userid").val());
  console.log("refresh");

  $.getJSON( "playGame.php", {displayGame:"true",gameid:$("#gameid").val(),userid:$("#userid").val()}, function( data ) {
  console.log("got checkGameState response: "+data['BuyIn']);
  $( "#myContent" ).empty();
  if(data['Status'] === "pending" )
  {
    $( "#myContent" ).append('<p>game is pending</p>');
  }
  else if (data['Status'] === "inProgress")
  {
    $( "#myContent" ).append('<p>game is in progress</p>');
    $( "#myContent" ).append('<p>hand is</p>');
    $( "#myContent" ).append('<p>pot is </p>');
    $( "#myContent" ).append('<p>stack is </p>');
  }
  else if (data['Status'] === "finalized")
  {
    $( "#myContent" ).append('<p>game is over</p>');
  }
  else
  {
    $( "#myContent" ).append('<p>invalid game state</p>');
  }

  setTimeout("refreshGamepage()",3000);
  });
}

这是在playGame页面中,当页面加载时运行该功能

<script type="text/javascript">
        console.log("running script");
        jQuery(document).ready(function($) {
            console.log("running ready");
            refreshGamepage();
        });
</script>

控制台日志在javascript中获得gamestate repsonse之前停止,因此它会让我相信php响应中存在错误

0 个答案:

没有答案