我的自动完成功能在Codeigniter中不起作用

时间:2018-09-01 14:22:24

标签: php jquery jquery-ui jquery-ui-autocomplete

myautocomple在codeiginiter中不起作用 甚至我的Chrome调试器->网络->都显示正确的结果。 这是我的查看文件代码:

<input type="text" class="form-control select_group product" style="text-transform: uppercase;" id="gang" name="gang" placeholder="Gangman Name" autocomplete="off" >
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">            
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$( "#gang" ).autocomplete({
source: "<?php echo base_url('Issue/getGangName/?');?>",
minLength: 3
});
});
</script>

这是我的控制器功能

public function GetGangName()
{
  $this->load->model('Issuemodel');
  $gangdata=$this->Issuemodel->GetGang();        
  echo json_encode($gangdata);
}

1 个答案:

答案 0 :(得分:0)

根据jQuery UI Autocomplete's docs,您的PHP处理程序应以如下形式返回数据:

[
  "NARAYAN SINGH CHUNDAWAT MLS",
  "RADHESHYAM SARGRA RMCH 2",
  // ...
]

或类似的形式:

[
  { "label": "some label", "value": "NARAYAN SINGH CHUNDAWAT MLS" },
  { "label": "some label", "value": "RADHESHYAM SARGRA RMCH 2" },
  // ...
];
// Note: should work with only the "value" key if you don't need the labels

使用原始数据的示例(我刚刚更改了相关的代码块):

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script type="text/javascript">
  $(document).ready(function() {
    $("#gang").autocomplete({
      source: [{
        "value": "NARAYAN SINGH CHUNDAWAT MLS"
      }, {
        "value": "RADHESHYAM SARGRA RMCH 2"
      }, {
        "value": "TRILOK CHANDRA SUTHAR RMCH 2"
      }, {
        "value": "ASLAM KHAN"
      }, {
        "value": "BHARAT SINGH"
      }, {
        "value": "Bhrth Raj Mehta RMCH 2"
      }, {
        "value": "CHANDRA PAL SINGH"
      }, {
        "value": "Deepak sharma"
      }, {
        "value": "DEVI LAL KACHI"
      }, {
        "value": "GAANGA SINGH RATHORE"
      }],
      minLength: 3
    });
  });
</script>

<input type="text" class="form-control select_group product" style="text-transform: uppercase;" id="gang" name="gang" placeholder="Gangman Name" autocomplete="off">