Welcome Guest, Not a member yet? Register   Sign In
How to use Jquery ajax in simple pagination ?
#1

[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: "&lt;?php echo site_url().'/ajaxcontrolleur/get_all_users';?&gt;",
            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
#2

[eluser]skunkbad[/eluser]
You should take a look at my Community Auth. It has a full working example of jQuery / CI pagination, and has search features too.
#3

[eluser]Samus[/eluser]
[quote author="skunkbad" date="1335338606"]You should take a look at my Community Auth. It has a full working example of jQuery / CI pagination, and has search features too.[/quote]
I just checked this out.

Can definately see myself using this in future.
#4

[eluser]ludo31[/eluser]
how to do that ??? for example how to ingrate that in my project for example and just about pagination,
#5

[eluser]skunkbad[/eluser]
[quote author="ludo31" date="1335355510"]how to do that ??? for example how to ingrate that in my project for example and just about pagination, [/quote]

Just look at my code and see how I did it. That should give you an understanding about how you can do the same for yourself.
#6

[eluser]ludo31[/eluser]
please ; for pagination for example what files I must see !! I ask that because there are a lot of files in a lot of folder and I don't know where pagination is concerned and also I can't test your code I don't know why because Wampserver don't detect it .

so for example in my case pagination : what files in view , model and controller are concerned ???

thanks




Theme © iAndrew 2016 - Forum software by © MyBB