2016-03-01 105 views
0

我正在Codeigniter HMVC中使用此ajax分頁。我得到我想要的輸出..但只在第一個鏈接。之後,下一頁不打開。或者當我點擊他們什麼都沒有發生。我檢查了元素,它有錯誤。AJAX分頁t jQuery-2.1.4.min.js:500(內部服務器錯誤)

Failed to load resource: the server responded with a status of http://http://localhost/TLC_HR/Job_Titles/ajaxPaginationData/10 500 (Internal Server Error) 
jQuery-2.1.4.min.js:4 POST http://localhost/TLC_HR/Job_Titles/ajaxPaginationData/10 500 (Internal Server Error)k.cors.a.crossDomain.send @ jQuery-2.1.4.min.js:4n.extend.ajax @ jQuery-2.1.4.min.js:4n.(anonymous function) @ jQuery-2.1.4.min.js:4onclick @ Job_Titles:524 

這是我的代碼。

Job_Titles.php - 控制器

<?php 

class Job_Titles extends MY_Controller{ 

    public function __construct(){ 

     parent::__construct(); 
     $this->load->model('Job_Titles_Model'); 
     $this->load->library('Ajax_pagination'); 
     $this->perPage = 10; 

    } 

// VIEW REDIRECTING ///////////////////////////////////////////////////////// 

    public function index(){ 

    /// view ajax config///// 

    $data = array(); 

    //total row count 
    $totalRec = count($this->Job_Titles_Model->getRows()); 

    //configuration 
    $config['first_link'] = 'First'; 
    $config['div'] = 'postList'; //parent div tag id 
    $config['base_url'] = base_url().'Job_Titles/ajaxPaginationData'; 
    $config['total_rows'] = $totalRec; 
    $config['per_page'] = $this->perPage; 

    $this->ajax_pagination->initialize($config); 

    //get data // must pass this to $this->load->view('content_view') and make it $this->load->view('content_view',$data,false) 
    $data['job_titles'] = $this->Job_Titles_Model->getRows(array('limit'=>$this->perPage,$this->uri->segment(3))); 

    $data['content_view'] = 'Job_Titles/jobtitles_read'; 
    $this->templates->admin_template($data); 

    } 

    public function add_view(){ 

    $data['content_view'] = 'Job_Titles/add_view'; 
    $this->templates->admin_template($data); 

    } 

//// pagination 

    public function ajaxPaginationData(){ 

    $page = $this->input->post('page'); 
     if(!$page){ 
      $offset = 0; 
     }else{ 
      $offset = $page; 
     } 

     //total row count 
     $totalRec = count($this->Job_Titles_Model->getRows()); 

     //pagination config 
     $config['first_link'] = 'First'; 
     $config['div'] = 'postList'; //parent div tag id 
     $config['base_url'] = base_url().'Job_Titles/ajaxPaginationData'; 
     $config['total_rows'] = $totalRec; 
     $config['per_page'] = $this->perPage; 

     $this->ajax_pagination->initialize($config); 

     //get post data 

     $data['job_titles'] = $this->Job_Titles_Model->getRows(array('start'=>$offset,'limit'=>$this->perPage)); 

     //load the view 
     $data['content_view'] = "'Job_Titles/jobtitles_read', $data, false"; 
     $this->templates->admin_template($data); 

    } 

} 

?> 

Job_Titles_Model.php - 模型

<?php 

class Job_Titles_Model extends CI_Model{ 

    function __construct() { 
     $this->table = 'job_titles'; 
    } 
///// VIEW PAGINATION ///////////////////////////////////////////////////////// 


     public function getRows($params = array()){ 

     $this->db->select('*'); 
     $this->db->from($this->table); 

     if(array_key_exists("start", $params) && array_key_exists("limit", $params)){ 

      $this->db->limit($params['limit'],$params['start']); 
     }elseif (!array_key_exists("start", $params) && array_key_exists("limit", $params)) { 
      $this->db->limit($params['limit']); 
     } 

     $query = $this->db->get(); 

     return ($query->num_rows() > 0)?$query->result_array():FALSE; 
    } 



} 


?> 

admin_template.php ---模板

  <li> 
      <a href="<?php echo base_url(); ?>Job_Titles"><i class="fa fa-circle-o"></i>Job Titles</a> 
      </li> 
      <div class="box-body">  
       <?php $this->load->view($content_view); ?> 
      </div> 

和add_view.php ---分頁顯示的地方。

<link rel="stylesheet" href="<?php echo base_url(); ?>assets/bootstrap/css/inputfield.css"> 

<div> 
    <center> 
     <fieldset> 


       <?php 

        echo form_open('Job_Titles/create'); 
       ?> 

       <p> 
        <label class="field" for="JOB_CODE"><span>*</span>Job Code:</label> 
        <input type = "text" name="JOB_CODE" class ="textbox-300"> 
        <label class = "error"><?php echo form_error("JOB_CODE"); ?></label> 
       </p> 
       <p> 
        <label class="field" for="JOB_NAME"><span>*</span>Job Name:</label> 
        <input type = "text" name="JOB_NAME" class ="textbox-300"> 
        <?php echo form_error("JOB_NAME"); ?> 
       </p> 



       <?php 
        echo form_submit('submit','Save'); 
        echo form_close(); 
       ?> 



     </fieldset> 
    </center> 
</div> 
+0

這真的有用嗎? $ data ['content_view'] =「'Job_Titles/jobtitles_read',$ data,false」;然後在你的視圖 load-> view($ content_view); ?> 我無法想象 – sintakonte

+0

沒有。哈哈。它讀作'Job_Titles/jobtitles_read',$ data,false.php哈哈。但我需要像'$ this-> load-> view($ content_view,$ data,false)''也許你可以幫助我。這是我認爲的可能的錯誤之一 –

回答

0

,我對我的評論給出一個答案基地(我將根據您的回覆延長我的答案,因爲我們要開始的地方清理這個爛攤子;))

首先在你的職稱控制器與您的內容視圖替換一部分與下面的代碼串

$data['content_view'] = array(
    "url" => "Job_Titles/jobtitles_read", 
    "data" => $data, 
    "blnReturnAsAString" => false 
); 

,並在你看來,你應該寫這個

$this->load->view($content_view["url"], $content_view["data"], $content_view["blnReturnAsAString"]);