Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载的Ajax页面表中的Codeigniter分页_Javascript_Php_Jquery_Ajax_Codeigniter - Fatal编程技术网

Javascript 加载的Ajax页面表中的Codeigniter分页

Javascript 加载的Ajax页面表中的Codeigniter分页,javascript,php,jquery,ajax,codeigniter,Javascript,Php,Jquery,Ajax,Codeigniter,另外,我知道这方面有很多答案,但它们看起来太复杂了,我只是一个使用语义UI的codeigniter和jquery的初学者,所以我在web开发方面遇到了困难 我想知道如何从使用ajax函数加载的页面在我的代码中实现分页。我发现将ajax与codeigniter结合起来非常困难,我不是一个非常熟练的程序员,所以请在这方面帮助我 加载所有数据的java脚本 function viewhardware(){ $.ajax({ type: "GET", url: "gethw",

另外,我知道这方面有很多答案,但它们看起来太复杂了,我只是一个使用语义UI的codeigniter和jquery的初学者,所以我在web开发方面遇到了困难

我想知道如何从使用ajax函数加载的页面在我的代码中实现分页。我发现将ajax与codeigniter结合起来非常困难,我不是一个非常熟练的程序员,所以请在这方面帮助我

加载所有数据的java脚本

function viewhardware(){
   $.ajax({
   type: "GET",
   url: "gethw",
        async: true,
  }).done(function( data ) {
  $('#hardware').html(data);
  });
}
控制器功能

public function gethw(){
        $this->load->model('asset_model');
        $this->data['hwares'] = $this->asset_model->get_allhw();
        $this->load->view('gethware',$this->data); 
    }
我的模型函数

public function get_allhw(){

        $this->db->select('*');
        $this->db->from('hardware h'); 
        $query = $this->db->get(); 
        if($query->num_rows() != 0)
        {   
            return $query->result_array();
        }
        else
        {
            return false;
        }

}
那景色呢

    <table class="ui compact table">
  <thead>
    <tr>
      <th></th>
      <th>Name</th>
      <th>Description</th>
      <th>Date Installed</th>
      <th>Serial No.</th>
      <th>PC ID</th>
      <th>Status</th>
      <th></th>
    </tr>
  </thead>
  <tbody>


  <center><i class="huge desktop icon""></i><h3>Hardwares</h3>
              <hr>
                <?php 

                   if(!empty($hwares)){
                      foreach($hwares as $hwares){
                             $hw_id = $hwares['hw_id'];
                             $hw_name = $hwares['hw_name'];
                             $hw_description = $hwares['hw_description'];
                             $hw_dateinstalled = $hwares['hw_dateinstalled'];
                             $hw_serialno = $hwares['hw_serialno'];
                             $hw_comp_id = $hwares['hw_comp_id'];
                             $hw_status = $hwares['hw_status'];
                     ?>
              <tr>
                  <th>
                   <?php echo $hw_id; ?>   
                  </th>
                  <th>
                  <?php echo $hw_name; ?>
                  </th>
                  <th>
                  <?php echo $hw_description; ?>
                  </th>
                  <th>
                  <?php echo $hw_dateinstalled; ?>
                  </th>
                  <th>
                  <?php echo $hw_serialno; ?>
                  </th>
                  <th>
                  <?php echo $hw_comp_id;?>
                  </th>
                  <th>
                     <button class="ui basic button"> 
                     <center><i class=" <?php if($hw_status==1){ echo 'green';}else{ echo 'red'; }; ?> 
                                desktop icon"></i>
                     </button>
                  </th>


                  <th><a id="editpc" class="ui button mini yellow"><i class="write icon"></i></a>
                  <a class="ui mini red button" href="#"><i class="remove icon"></i></a></th>       


                 </tr>

                     <?php 
                        }
                        }
                      ?>

 </tbody>
</table>     

名称
描述
安装日期
序列号。
个人计算机ID
地位
桌面图标“>

您可以使用Ajax分页库

您将找到如何使用它的示例

您的控制器应该如下所示:

function __construct() {
        parent::__construct();
        $this->load->library('Ajax_pagination');
        $this->perPage = 1;
    }
public function gethw(){
        $this->load->model('asset_model');
        
        //total rows count
        $totalRec = count($this->asset_model->getRows());
        
        //pagination configuration
        $config['first_link']  = 'First';
        $config['div']         = 'div-to-refresh'; //parent div tag id
        $config['base_url']    = base_url().'controller/ajaxPaginationData';
        $config['total_rows']  = $totalRec;
        $config['per_page']    = $this->perPage;
        
        $this->ajax_pagination->initialize($config);
        
        //get the posts data
        $this->data['hwares'] = $this->asset_model->getRows(array('limit'=>$this->perPage));
        $this->load->view('view1',$this->data); 
    }
 function ajaxPaginationData()
    {
        $page = $this->input->post('page');
        if(!$page){
            $offset = 0;
        }else{
            $offset = $page;
        }
        
        //total rows count
        $totalRec = count($this->asset_model->getRows());
        
        //pagination configuration
        $config['first_link']  = 'First';
        $config['div']         = 'div-to-refresh'; //parent div tag id
        $config['base_url']    = base_url().'controller/ajaxPaginationData';
        $config['total_rows']  = $totalRec;
        $config['per_page']    = $this->perPage;
        
        $this->ajax_pagination->initialize($config);
        
        //get the posts data
       $this->data['hwares'] = $this->asset_model->getRows(array('start'=>$offset,'limit'=>$this->perPage));
        
        //load the view
        $this->load->view('view2', $this->data, false);
    }
您必须将视图分成两部分 视图1

<div id="hardware">
<div id="div-to-refresh">
    <?php $this->load->view('view2',$this->data); ?> 
</div>
<div id="pagination"><?php echo $this->ajax_pagination->create_links(); ?></div>  
</div>

视图2

<table class="ui compact table">
  <thead>
    <tr>
      <th></th>
      <th>Name</th>
      <th>Description</th>
      <th>Date Installed</th>
      <th>Serial No.</th>
      <th>PC ID</th>
      <th>Status</th>
      <th></th>
    </tr>
  </thead>
  <tbody>


  <center><i class="huge desktop icon""></i><h3>Hardwares</h3>
              <hr>
                <?php 

                   if(!empty($hwares)){
                      foreach($hwares as $hwares){
                             $hw_id = $hwares['hw_id'];
                             $hw_name = $hwares['hw_name'];
                             $hw_description = $hwares['hw_description'];
                             $hw_dateinstalled = $hwares['hw_dateinstalled'];
                             $hw_serialno = $hwares['hw_serialno'];
                             $hw_comp_id = $hwares['hw_comp_id'];
                             $hw_status = $hwares['hw_status'];
                     ?>
              <tr>
                  <th>
                   <?php echo $hw_id; ?>   
                  </th>
                  <th>
                  <?php echo $hw_name; ?>
                  </th>
                  <th>
                  <?php echo $hw_description; ?>
                  </th>
                  <th>
                  <?php echo $hw_dateinstalled; ?>
                  </th>
                  <th>
                  <?php echo $hw_serialno; ?>
                  </th>
                  <th>
                  <?php echo $hw_comp_id;?>
                  </th>
                  <th>
                     <button class="ui basic button"> 
                     <center><i class=" <?php if($hw_status==1){ echo 'green';}else{ echo 'red'; }; ?> 
                                desktop icon"></i>
                     </button>
                  </th>


                  <th><a id="editpc" class="ui button mini yellow"><i class="write icon"></i></a>
                  <a class="ui mini red button" href="#"><i class="remove icon"></i></a></th>       


                 </tr>

                     <?php 
                        }
                        }
                      ?>

 </tbody>
</table>

名称
描述
安装日期
序列号。
个人计算机ID
地位
桌面图标“>
我不能为您编写所有代码,但这可以帮助您。
在您的模型中进行更改以与此匹配。

不鼓励仅链接答案,13分钟后回答?我已经尝试过了,但对我的级别来说太复杂了,所以我确实需要帮助。@JayaVishwakarma it无法工作在控制台中收到错误无法加载资源:服务器以状态500响应(内部服务器错误)请帮助抱歉,但我只能在完全访问您的代码时才能帮助您。您从哪里得到struk??