我的 $.ajax 函数中的成功函数有问题 在 javascript 文件中:
$("#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');
}
});
我的 Controller 函数
<?php
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'
**
最佳答案
base_url()
是一个 Codeigniter 函数 (php),在你的 $ajax 函数中你使用了 javascript 变量 base_url,它不是定义。
为了让 php base_url() 进入您的 $ajax 函数,您需要回显 php 函数,更改为以下行:
url: "<?php echo base_url() ?>Search_controller/testing_controller",
关于javascript - 带有 ajax 的 Codeigniter : success function not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58357540/