在控制器中停止ajax函数setinterval重定向

时间:2014-01-05 06:19:31

标签: javascript php jquery ajax

ajax电话

     <script type="text/javascript">
var timeOutID =0;
var checkScore =  function ()
  {
$.ajax({
  url: "<?php echo 'http://127.0.0.1/ProgVsProg/main/checkScore'?>",
  success:function(response){
    if(response){
       $('#maincontent1').html(response);
     timeOutID = setTimeout(checkScore, 3000);
      } 
    else
      {
     clearTimeout(timeOutID); 
    }
  }
});
}
timeOutID = setTimeout(checkScore,1000);

控制器

    public function checkScore(){
    $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);
                redirect('main/secondRound');
                }
        else if($Rscore == '1'){
        $cID =$this->lawmodel->getID($row->requestedID);    
        redirect('main/secondRound');   
        }           
    }
}

secondRound Controller

public function secondRound(){
    $category = 'medium';
    $data['results'] = $this->lawmodel->roundTwoQuestion($category);
    $data['content'] = 'battlePage';
    if($this->session->userdata('is_logged_in'))
    {
        $this->load->view('includes/template2',$data);
    }
    else
    {
        redirect('main/restricted');
    }
}

我的问题是如何使用setTimeout()停止执行ajax调用,因为它从重定向到另一个控制器的控制器获取...而我的另一个问题是ajax函数将直接执行,即使它尚未满足控制器中的条件。它将返回空白页面..

PLSS帮助!!我是ajax的新人.. :(

0 个答案:

没有答案
相关问题