gpt4 book ai didi

javascript - codeigniter 中的自动完成功能不显示任何内容

转载 作者:行者123 更新时间:2023-12-01 05:17:15 24 4
gpt4 key购买 nike

嘿,我正在 codeigniter 中创建一个自动完成搜索字段,我尝试使用下面的代码在 codeigniter 中进行自动完成。但它对我不起作用。在自动完成文本字段中不显示任何内容。任何人都可以找到问题

数据显示为未定义的成功函数

这是我的观点:

View
<script >
$(document).ready(function() {
$("#trackerid").change(function(){
var var_locoid= $("#trackerid option:selected").val();
alert(var_locoid);
$( "#deliverylocation" ).autocomplete({

source: function(request, response) {
var auto_data= $("#deliverylocation").val();
alert(auto_data);

//alert(var_locoid);
$.ajax({
url:"http://localhost/testcontroller/test/lookup",
type:"POST",
datatype:'json',
data:{'var_locoid' :var_locoid,'auto_data':auto_data},
success: function(data){
response(data);
alert(data);
}
});
},
minLength: 1
});
});});
</script>

<input type="text" name="deliverylocation" id="deliverylocation" placeholder="Enter your area " >

Controller

    function lookup()
{
$citys = $this->input->post('var_locoid');
$auto_text = $this->input->post('auto_data');

//var_dump($citys);
//$data['response'] = 'false';
$place = $this->Demo_model->load_places($citys,array('keyword' => $auto_text));
$json_array = array();
foreach ($place as $row){
array_push($json_array, $row->locationtext);
}
//echo json_encode($place);
echo json_encode($json_array);
}



Model

function load_places($citys,$auto_text)
{
//$this->db->select('locationtext');
$this->db->select('locationtext');
$this->db->like('locationtext', $auto_text);
$this->db->from('tbl_location');
$array = array('cityautocode' => $citys);
$this->db->where($array);
//$this->db->->where('cityautcode', $place);
$query= $this->db->get();
//echo $this->db->last_query();

return $query->result();

}

最佳答案

我正在使用 https://www.devbridge.com/sourcery/components/jquery-autocomplete/ 中的自动完成模式

这是我的 Controller :

$arrayData = $this->CRUD_model->getSelect("id as data, name as value, purchase_price","articles")->result_array();
echo json_encode($arrayData);

我的观点:

$(document).ready(function(){
// $("body").addClass("sidebar-collapse");
var dataArticles = $.parseJSON(getArticles());
$("input[name='articles_name']").devbridgeAutocomplete({
lookup: dataArticles,
onSelect: function(suggestion) {
$("input[name='articles_id']").val(suggestion.data);
},
showNoSuggestionNotice: true,
noSuggestionNotice: 'Barang tidak ditemukan',
noCache: true,
minChars: 2,
})
})

function getArticles(){
result = null;
$.ajax({url: '<?= base_url();?>panel/purchasing/request/getArticles',type: 'get',dataType: 'html',async: false,success: function(data) {result = data;} });
return result;
}

在此示例中,我使用查找,因此打开页面时加载的所有自动完成值,请注意 id 必须命名为“data”,标签必须命名为“value”。

关于javascript - codeigniter 中的自动完成功能不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48293762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com