jquery自动完成不会打印结果

jquery自动完成不会打印结果,jquery,css,autocomplete,jquery-autocomplete,Jquery,Css,Autocomplete,Jquery Autocomplete,我第一次尝试使用jQueryUI的autocomplete特性,但我无法让它正常工作 javascript代码: $("#search_input").autocomplete({ source: function(request, response) { $.getJSON( "do.php", { OP: "news_search", category: cat_id, get: request }, function(result){ /*response($.ma

我第一次尝试使用jQueryUI的
autocomplete
特性,但我无法让它正常工作

javascript代码:

$("#search_input").autocomplete({
  source: function(request, response) {
    $.getJSON( "do.php", { OP: "news_search", category: cat_id, get: request }, function(result){
      /*response($.map(result, function(item) {
        return item.NAME;
      }));*/
      response(result);
      console.log(result);
    })
  },
  minLength: 2
});
它返回数据,但不会显示:

我甚至尝试添加一些css,看看它是否有效:

.ui-autocomplete{
    position: absolute;
    z-index: 1000;
    border: 1px solid red;
}
$("#search_input").autocomplete({
    source: function(request, add) {
        $.getJSON("do.php", { OP: "news_search", category: cat_id, get: request }, function(results){

          consoloe.log(results)
          var suggestions = [];

          $.each(results, function(i, val){
            suggestions.push(val.headline)
          });

          add(suggestions);

        });
    },
    minLength: 2
});

JSON应该返回
label
value
参数,而不是
id
headline

具有标签和值属性的对象数组:
[{标签:“Choice1”,值:“value1”},…]


我最后读了这篇文章:

这就是我使用它的方式,它的工作原理:

.ui-autocomplete{
    position: absolute;
    z-index: 1000;
    border: 1px solid red;
}
$("#search_input").autocomplete({
    source: function(request, add) {
        $.getJSON("do.php", { OP: "news_search", category: cat_id, get: request }, function(results){

          consoloe.log(results)
          var suggestions = [];

          $.each(results, function(i, val){
            suggestions.push(val.headline)
          });

          add(suggestions);

        });
    },
    minLength: 2
});

但是怎么做呢?硬编码?
result
中的数据由
print\r(json\u encode($data['search\u results'))返回
是用mysql查询的结果构建的。我不熟悉PHP,但是如果直接读取字段名,我假设您需要在查询中为字段别名。如果你对此有问题,最好问一个新问题。如果我有这样的问题:
[{label:“123155”,value:“Welcom to Stackoverflow”},
是正确的吗?是的,应该可以,尽管你可能想要label=Welcome,value=123155。
Object{value=“1545520”,label=“Movistar”}
仍然没有成功,现在。。。它没有显示任何东西。。。甚至连图中箭头所在的那个小东西都没有