20 January 2021

How to use ajax in Codeigniter?

 Use ajax in Codeigniter


Paste in View

<script>
$(document).ready(function(){
$(".ajax_bt").click(function(e) {
e.preventDefault();  
    var person = $('#person').val();
    var phone = $('#phone').val();
    var email = $('#email').val();
    var password = $('#password').val();
//alert(person+''+''+phone+''+email+''+password);
    $.ajax({
        url: "<?php echo base_url('index.php/Welcome/insert_data_with_ajax'); ?>",
        data: {
'person':person,
'phone':phone,
'email':email,
'password':password
}, // change this to send js object
        type: "post",
        success: function(data){
           //document.write(data); just do not use document.write
           console.log(data);
        }
      });
});
});
</script>

Paste in Controller



class Welcome extends CI_Controller {

 public function __construct()
    {
        parent::__construct();
        
        $this->load->library('session');
        $this->load->helper('html');
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->helper('file');
        $this->load->library('form_validation');
      
        $this->load->model('Customer_model');

       
    }
 

public function insert_data_with_ajax() {
echo $person = $this->input->post('person');
echo 'jassi';
//$data['main_content']='ajax';
//$this->load->view('template',$data);
}


}

No comments:

Post a Comment

How to create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...