在clearTImeout方面需要帮助

时间:2014-01-08 14:43:50

标签: ajax codeigniter

的Ajax

<script type="text/javascript">
 var stopTime =0;
 var scoreCheck =  function ()
    {
      $.ajax({
      url: 'http://127.0.0.1/ProgVsProg/main/checkScoreRoundOne',
      success:function(output){
        if(output !='Instruction'){
       console.log(output);
                clearTimeout(scoreCheck);
            }
        else 
            console.log(output);
            stopTime = setTimeout(scoreCheck, 1000);  
    }
  });
}
 stopTime = setTimeout(scoreCheck,1000);
 </script>

控制器

public function checkScoreRoundOne(){
    $id = $this->session->userdata('userID');
    $battleID = $this->lawmodel->getBattle($id);
    foreach($battleID as $row){
        $Rscore = $row->requestedScore;
        $Cscore = $row->challengerScore;
          if($Cscore == '1'){
        $rID = $this->lawmodel->getID($row->challengerID);
          foreach($rID as $row){
          echo $row->username."Got the correct answer"; 
             }
           }
          else if($Rscore == '1'){
           $cID =$this->lawmodel->getID($row->requestedID);
           foreach($cID as $row){
                echo $row->username."Got the correct answer";
            }
        }
            else 
                echo "Instruction";

        }
}

我在上面的代码中感到困惑

  • 在ajax中,为什么当输出!='指令'时它会显示“指令”,当输出=='指令'时,它会显示$ row-&gt;用户名得到了正确答案。
  • 当Cscore == 1或Rscore == 1时,如何停止setTimeout? 我认为cleartimeout不会只停止setTimeout ..

Plss帮助......我是ajax中的新人.. 我正在使用codeigniter

1 个答案:

答案 0 :(得分:0)

关于clearTimeout:

clearTimeout(stopTime);