Codeigniter with ajax: success function not working Codeigniter with ajax: success function not working codeigniter codeigniter

Codeigniter with ajax: success function not working


base_url() is a Codeigniter function (php), in your $ajax function you use the javascript variable base_url, which is not defined.

in order to get the php base_url() into your $ajax function you need to echo out the php function, changing to this line:

url: "<?php echo base_url() ?>Search_controller/testing_controller",


Change your URL as follows

url:"<?php echo base_url()?>index.php/Search_controller/testing_controller",

I tested your code and its working file.


I find the solution is because of CSRF security

$("#country select").change(function () {              var country_value= $(this).val();              var data = { /* params  */                    "country": country_value,                     "state": '001'                };              data[csfr_token_name] = $.cookie(csfr_cookie_name);            $.ajax({                url:base_url + "Search_controller/testing_controller",                 method: 'post',                data: data,                dataType: 'json',                success: function(data){                    console.log('done : ' + data);                  },                   error: function (reponse) {                console.log('Problem with ajax');                }            });

This Code Working