2015-11-04 81 views
0

当我检查一些联赛,我想从数据库中加载季节,我对那个联盟有什么。如何在没有刷新的情况下加载CI控制器功能?

我试过这段代码。

test.php的观点

<script type="text/javascript"> 
     $(document).ready(function() { 
      var site_url = "<?php echo base_url('/system/getseasons/SC0'); ?>"; //SC0 is here as example, there will be selected league 
      $("#season").load(site_url); 
     }); 
    </script> 

System.php控制器

public function getseasons($div){ 
    $seasons = $this->sys_model->getseasonsforleague($div); 
    $mode = ''; 
    foreach($seasons->result() as $season){ 
     if($season->Season != ''){ 
     $newseason = $this->season_filter($season->Season); 
     if($mode == 'edit' and $system->bet_venue !== NULL){ 
     $season_arr = explode(";",$system->seasons); 
      foreach($season_arr as $seas){ 
       if($season->Season == $seas){ 
       echo "<input type='checkbox' name='season[]' checked='checked' value=". $season->Season .">" . $newseason . "</input><br>";    
       } 
      } 
      if($season->Season != $seas){ 
       echo "<input type='checkbox' name='season[]' value=". $season->Season .">" . 
       $newseason . "</input><br>";    

      } 
     } 
     else{ 
      echo "<input type='checkbox' name='season[]' value=". $season->Season .">" . $newseason . "</input><br>";  } 
     } 
    } 
} 

注:因为此控制器100%的作品时,我手动去这个链接: 网站。 com/system/getseasons/SC0我获得了SC0联赛的所有赛季。

和Sys_model.php模式

public function getseasonsforleague($div){ 
    $this->db->select('Season'); 
    $this->db->where('Div',$div); 
    $this->db->group_by('Season'); 
    return $this->db->get('historic'); 
} 

当我检查浏览器控制台我看到错误:

GET https://www.example.com/system/getseasons/SC0 404 (OK)send @ jquery.min.js:5m.extend.ajax @ jquery.min.js:5m.fn.load @ jquery.min.js:5(anonymous function) @ test:11j @ jquery.min.js:2k.fireWith @ jquery.min.js:2m.extend.ready @ jquery.min.js:2J @ jquery.min.js:2

但有更多的时间,此链接:

https://www.example.com/system/getseasons/SC0

而且我想这:

var site_url = "<?php echo base_url('/index.php/system/getseasons/SC0'); 

但同样404

UPDATE:网络选项卡 network

+0

使用AJAX更新视图而不刷新 – AkshayP

+0

@ A.P。如果你能举一些例子,我还没有经验的AJAX。 – DocNet

+0

@ A.P。是不是'$ .load'一个jquery ajax函数? – madalinivascu

回答

0

试试这个

` var site_url = "<?php echo base_url(); ?>"+'/system/getseasons/SC0';` 
+0

404: GET https://www.example.com/system/getseasons/SC0 404(OK)send @ jquery.min.js:5m.extend.ajax @ jquery.min.js:5m.fn。 load @ jquery.min.js:5(匿名函数)@test:11j @ jquery.min.js:2k.fireWith @jquery.min.js:2m.extend.ready @jquery.min.js:2J @ jquery。 min.js:2 – DocNet

+0

检查BASE_URL –

+0

BASE_URL是正确的,但看到这个控制台: (匿名函数)\t @ \t测试:11 第11行是这样的: $( “#季节”)负载( SITE_URL); 它看起来像.load功能将无法正常工作? – DocNet

0

试试这个:

var site_url = "<?php echo base_url(); ?>"+'system/getseasons/SC0/'; 
+0

像@Mayank Vadiya一样的答案,但不会工作。我试过这个'system/getseasons/SC0';和这个'/ system/getseasons/SC0'; 404 – DocNet

+0

更新了我的回答 – madalinivascu

+0

不再404: GET https://www.example.co/system/getseasons/SC0/ 404(OK)send @ jquery.min.js:5m.extend.ajax @ jquery.min。 js:5m.fn.load @ jquery.min.js:5 (anonymous function)@ test:11 j @ jquery.min.js:2k.fireWith @ jquery.min.js:2m.extend.ready @ jquery .min.js:2J @ jquery.min.js:2 – DocNet

相关问题