AJAX分页jQuery-2.1.4.min.js:500(内部服务器错误)

时间:2016-03-01 12:24:49

标签: php ajax codeigniter templates pagination

我正在使用Codeigniter HMVC中的这个ajax分页。我得到了我想要的输出..但只在第一个链接上。然后,接下来的页面不会打开。或者当我点击它们时没有任何反应。我检查了元素,但它有错误。

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 - model

<?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 --- template

          <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>

1 个答案:

答案 0 :(得分: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"]);