Php 选择2错误404(未找到)

Php 选择2错误404(未找到),php,ajax,codeigniter,jquery-select2,Php,Ajax,Codeigniter,Jquery Select2,我的select2有一些问题,我正在按照示例进行操作,但它没有显示结果。我使用ajax使它更简单 错误 404 (Not Found) public function GetCountryName(){ $search = $this->input->get('search'); $query = $this->datacomplete->Get_Country($search, 'name'); echo json_encode($query)

我的select2有一些问题,我正在按照示例进行操作,但它没有显示结果。我使用ajax使它更简单

错误

404 (Not Found)
public function GetCountryName(){
    $search = $this->input->get('search');
    $query = $this->datacomplete->Get_Country($search, 'name');
    echo json_encode($query);
}
html

<div class="form-group">
   <label class="col-sm-4 control-label">Product Name</label>
   <div class="col-sm-6">
      <select class="productName form-control" name="productName" id="productName"></select>
   </div>
</div>
class Datacomplete extends CI_Model{

    public function Get_Country($search) {
        $this->db->select('*');
        $this->db->limit(10);
        $this->db->from('auto');
        $this->db->like('name', $search);
        return $this->db->get('auto')->result_array();
    }
}
return $this->db->get('auto')->result_array();

to

return $this->db->get()->result_array();
型号

<div class="form-group">
   <label class="col-sm-4 control-label">Product Name</label>
   <div class="col-sm-6">
      <select class="productName form-control" name="productName" id="productName"></select>
   </div>
</div>
class Datacomplete extends CI_Model{

    public function Get_Country($search) {
        $this->db->select('*');
        $this->db->limit(10);
        $this->db->from('auto');
        $this->db->like('name', $search);
        return $this->db->get('auto')->result_array();
    }
}
return $this->db->get('auto')->result_array();

to

return $this->db->get()->result_array();
ajax

$("#productName").select2({
    ajax: {
        url: "<?php echo base_url('auto_config/GetCountryName')?>",
        dataType: 'json',
        delay: 250,
        data: function (params) {
            return {
                search: params.term // search term
            };
        },
        processResults: function (data) {
            var results = [];

            $.each(data, function(index, item) {
                results.push({
                    id: item.id,
                    text: item.name
                });
            });
            return {
                results: results
            };
        }
    }
});
url: "<?php echo base_url('auto_config/GetCountryName')?>"

to


url: "<?php echo site_url('auto_config/GetCountryName')?>"
$(“#产品名称”)。选择2({
阿贾克斯:{
url:“”,
数据类型:“json”,
延误:250,
数据:函数(参数){
返回{
搜索:params.term//search term
};
},
processResults:函数(数据){
var结果=[];
$。每个(数据、功能(索引、项目){
结果:推({
id:item.id,
text:item.name
});
});
返回{
结果:结果
};
}
}
});

找不到错误消息404,我不知道原因。

问题在这里:
url:,
在ajax中。控制器中的方法
GetCountryName()
应该可以在某些路径中访问,例如
/get\u countries
,然后您可以向它发送ajax。

我解决了它

型号

<div class="form-group">
   <label class="col-sm-4 control-label">Product Name</label>
   <div class="col-sm-6">
      <select class="productName form-control" name="productName" id="productName"></select>
   </div>
</div>
class Datacomplete extends CI_Model{

    public function Get_Country($search) {
        $this->db->select('*');
        $this->db->limit(10);
        $this->db->from('auto');
        $this->db->like('name', $search);
        return $this->db->get('auto')->result_array();
    }
}
return $this->db->get('auto')->result_array();

to

return $this->db->get()->result_array();
ajax

$("#productName").select2({
    ajax: {
        url: "<?php echo base_url('auto_config/GetCountryName')?>",
        dataType: 'json',
        delay: 250,
        data: function (params) {
            return {
                search: params.term // search term
            };
        },
        processResults: function (data) {
            var results = [];

            $.each(data, function(index, item) {
                results.push({
                    id: item.id,
                    text: item.name
                });
            });
            return {
                results: results
            };
        }
    }
});
url: "<?php echo base_url('auto_config/GetCountryName')?>"

to


url: "<?php echo site_url('auto_config/GetCountryName')?>"
url:“
到
网址:“

你能确认你的
url:“,
的HTML输出是你所期望的吗?在url
url:“
还要检查您是否已在配置中设置了基本url。php@IsThisJavascript它的auto_config是控制器名,GetCountryName是函数名controller@Mr.ED它不会显示结果,我检查了。@ankitsuthar我已经完成了,谢谢你的建议。顺便说一句,所以我需要将它更改为
/auto\u config/GetCountryName