[eluser]ludo31[/eluser]
Hello ;
I try to use ajax in jquery : so I create a simple code , it works : it shows the result
in my view :
Code:
<body>
<button type="button" name="getdata" id="getdata">Get Data.</button>
<div id="result_table">
<p> je suis de retour ves 16 h </p>
</div>
[removed]
$('#getdata').click(function(){
$.ajax({
url: "<?php echo site_url().'/ajaxcontrolleur/get_all_users';?>",
type:'POST',
dataType: 'json',
success: function(output_string){
$("#result_table p").empty().html(output_string).show(1500);
} // End of success function of ajax form
}); // End of ajax call
});
[removed]
and in my controller :
Code:
public function get_all_users(){
echo json_encode( $this->modelajax->ajaxmodel());
}
and in my model I create json code .
Code:
public function ajaxmodel ()
{
$query = $this->db->get('articles');
if($query->num_rows > 0){
$header = false;
$output_string = "";
$output_string .= "<table border='1'>\n";
foreach ($query->result_array() as $row){
$output_string .= "<tr>\n";
$output_string .= "<th>{$row['titre']}</th>\n";
$output_string .= "</tr>\n";
}
$output_string .= "</table>\n";
}
else{
$output_string = "There are no results";
}
return $output_string ;
}
but now , we suppose that there is a pagination in my code something like that :
Code:
function index(){
/*
$data['title']='079';
$data['rows']='en raison de la maison ';
$string = $this->load->view('site_view',$data);
*/
// $this->load->view('site_pagination');
$config['base_url'] = 'http://localhost/CodeIgniter1/index.php/site/index';
$config['total_rows'] = $this->db->get('chaussure')->num_rows();
$config['per_page'] = 2;
$config['num_links'] = 2;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$config['next_link'] = '<<';
$config['prev_link'] = '>>';
$this->pagination->initialize($config);
$data['rows'] = $this->db->get('chaussure',$config['per_page'],$this->uri->segment(3));
//var_dump($config);exit ;
$this->load->view('site_pagination',$data);
}
how to use ajax with this code , may be we must change the code and insert json code in
Code:
$data['rows'] = $this->db->get('chaussure',$config['per_page'],$this->uri->segment(3));
and here don't we change anything
Code:
$config['base_url'] = 'http://localhost/CodeIgniter1/index.php/site/index';
$config['total_rows'] = $this->db->get('chaussure')->num_rows();
$config['per_page'] = 2;
$config['num_links'] = 2;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$config['next_link'] = '<<';
$config['prev_link'] = '>>';
$this->pagination->initialize($config);
thanks