I have a problem with success function in my $.ajax function
in javascript file:
$("#country select").change(function () {
var country_value = $(this).val();
$.ajax({
url:base_url + "Search_controller/testing_controller",
method: 'post',
data: {country_val: country_value },
dataType: 'json',
success: function(data){
console.log('done : ' + data);
},
error: function (reponse) {
console.log('Problem with ajax');
}
});
my Controller function
class Search_controller extends CI_Controller{
public function index(){
}
public function testing_controller(){
$data ="statessssssss";
echo json_encode($data);
}
}
?>
**
The Problem is the codes do nothing, i don't know what the problem
Always return to me in Browser log 'Problem with ajax'
**
Answer
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
No comments:
Post a Comment