简体   繁体   English

jQuery-UI自动完成数据未显示

[英]jQuery-UI autocomplete data not showing

jQuery: jQuery的:

function search($id, $column) {
  $("#" + $id).autocomplete({
    source: function(request, response) {
      jQuery.post("<?php echo base_url().'index.php/Auto_complete/item_search'?>", {
        Query: request.term,
        column: $column
      }, function(data) {
        response(data);
      });
    }
  });
}

HTML: HTML:

<input type="text" class="form-control English_name" id="English_name" name="English_name" placeholder="Enter Item Name (English)" onchange="product_name()" onkeyup="search('English_name', 'English_name')" autocomplete="off">

AJAX Output: AJAX输出:

["Styler King 6 Card Holder  (Set of 1, Khaki)","ds 18 sticker","famous sticker","wx sticker","lk small sticker","LX Sticker"]

Anyone can please help me why data is not showing and How can I display data in jQuery UI autocomplete? 任何人都可以帮助我,为什么不显示数据以及如何在jQuery UI自动完成中显示数据?

It's not clear what you're trying to accomplish with your code. 目前尚不清楚您要用代码完成什么。

Here is an example that you may find helpful: 这是一个示例,您可能会发现有帮助:

https://jsfiddle.net/Twisty/t1ruyg11/ https://jsfiddle.net/Twisty/t1ruyg11/

JavaScript 的JavaScript

var myData = [
  "Styler King 6 Card Holder  (Set of 1, Khaki)",
  "ds 18 sticker",
  "famous sticker",
  "wx sticker",
  "lk small sticker",
  "LX Sticker"
];

$(function() {
  $("#English_name").autocomplete({
    source: function(req, resp) {
      $.post("/echo/json/", {
        json: JSON.stringify(myData)
      }, function(data) {
        resp($.ui.autocomplete.filter(data, req.term));
      });
    }
  });
});

Now, considering your code, you may want to try something like the following: 现在,考虑您的代码,您可能想要尝试如下操作:

function search(t, c){
  var url = "<?php echo base_url().'index.php/Auto_complete/item_search'; ?>";
  var query = {
    Query: t.trim(),
    column: c
  };
  $.post(url, query, function(results){
    if(results.length){
      return results;
    } else {
      return [];
    }
  });
}

$(function(){
  $("#English_name").autocomplete({
    source: function(request, response){
      response(search(request.term), $column);
    }
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM