Controller: test.phpAjax Seitennummerierung funktioniert nicht im Codeigniter?
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller
{
function __construct()
{
parent :: __construct();
$this->load->helper(array('form', 'url', 'captcha', 'email'));
$this->load->model('dependent_field');
$this->load->library('curl');
}
public function get_exam_college($offset=null)
{
$this->load->library('pagination');
$config['base_url'] = base_url().'test/get_exam_college/';
$config['total_rows'] = $this->dependent_field->count_field_exam_college($field);
$config['per_page'] = 10;
$config['full_tag_open'] = '<ul class="pagination" id="search_page_pagination">';
$config['full_tag_close'] = '</ul>';
$config['cur_tag_open'] = '<li class="active"><a href="javascript:void(0)">';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_close'] = '</a></li>';
$config['first_link'] = 'First';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['next_link'] = FALSE;
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = FALSE;
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['page_query_string'] = FALSE;
$this->pagination->initialize($config);
$field=$this->input->post('field');
$data['field'] = $this->dependent_field->field_exam_college($field, $config['per_page'],$offset);
$this->load->view('exam-centers-colleges',$data);
}
}
Ansicht: Prüfung-Zentren-colleges.php
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<?php
foreach ($field as $fetch)
{
?>
<div class="col-lg-12" id = "box" >
<div id="about">
<ul id="list">
<li><?php echo $fetch['college_name']; ?></li>
<li><?php echo $fetch['address']; ?></li>
</ul>
</div>
</div>
<?php
echo $this->pagination->create_links();
}
?>
<script type="text/javascript">
$(function(){
$('body').on('click','ul#search_page_pagination>li>a',function(e){
e.preventDefault();
var Pagination_url = $(this).attr('href');
$.ajax({
url:Pagination_url,
type:'POST',
success:function(data)
{
var $page_data = $(data);
$('#box').html($page_data.find('div#box'));
$('table').addClass('table');
}
});
});
});
</script>
Modell: dependent_field.php
<?php
class Dependent_field extends CI_Model
{
function __construct()
{
parent::__construct();
}
public function field_exam_college($field)
{
$this->db->select('college_name, field, city, state, address, website, courses');
$this->db->from('all_colleges');
$where = "field = '$field'";
$this->db->where($where);
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
public function count_field_exam_college($field)
{
$this->db->select('college_name, field, city, state, address, website, courses');
$this->db->from('all_colleges');
$where = "field = '$field'";
$this->db->where($where);
$query = $this->db->get();
$result = $query->count();
return $result;
}
}
In diesem Code habe ich einen Index haben. php-Datei und ich rufe exam-collections.php-Datei an, wenn ich auf Senden klicke. Jetzt möchte ich Ajax-Seitenzahlen verwenden, aber es funktioniert immer noch nicht. Ich weiß nicht warum und wo mache ich mich falsch. Also, wie kann ich Ajax Paginierung verwenden? Bitte helfen Sie mir.
Thank
hallo, warum verwenden Sie nicht dataType: 'JSON' oder 'Text', AJAX muss einige Daten von Methode, die Sie in URL festgelegt. –