• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ajax success is not working in codeigniter

#7
I still use CI 3 not 4 yet, however let me give you a working example of Ajax which might help you. 

The example below is about "updating some informations of a company" 

AJAX : 

Code:
<script type="text/javascript">
                $(document).ready(function(){
                  $('#send-button').click(function(e){

                    e.preventDefault;

                    var company_id = $('#company_id').val();
                    var company_name = $('#company_name').val();
                    var company_about = $('#company_about').val();

                    $.ajax({
                      url : "<?php echo base_url('YourController/function_name_please');?>",
                      method : "POST",
                      data : {company_id:company_id,company_name:company_name, company_about:company_about},
                      success:function(data)
                    {
                       
                setTimeout(function(){// wait for 0,2 secs 
               location.reload(); // then reload the page.
      }, 200);

                      },
          error: function(data){
              console.log('There is a mistake somewhere');
          }
                    }); // ajax ends here

                  });
                });
              </script>

Controller : 


PHP Code:
public function function_name_please(){

$company_id $this->input->post('company_id');
$company_name $this->input->post('company_name');
$company_about $this->input->post('company_about');

$data = array(
  'company_name' => $company_name,
  'company_about' => $company_about
);

$this->load->model('Backend_model');
$this->Backend_model->lets_update_it($data$company_id);

Reply


Messages In This Thread
RE: Ajax success is not working in codeigniter - by demyr - 09-26-2019, 02:00 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.