Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery自动完成返回数组_Jquery_Jquery Autocomplete - Fatal编程技术网

jQuery自动完成返回数组

jQuery自动完成返回数组,jquery,jquery-autocomplete,Jquery,Jquery Autocomplete,这是我的密码: $("#input-search").autocomplete({ source: function(request, response) { $.get('EmployeeSearchList.igx', { name: request.term }, function(data) { response(data.split('\n')); }

这是我的密码:

$("#input-search").autocomplete({
    source: function(request, response) {
            $.get('EmployeeSearchList.igx', { name: request.term }, 
            function(data) {
                response(data.split('\n'));
                }
            );
        }
    });
EmployeeSearchList.igx返回这种格式

[{label:"JP Fortes", value:"199829"},{label:"Jeffrey Dante", value:"200507"}]
我如何看待这一点作为回报

<li value="199829">JP Fortes</li>
<li value="200507">Jeffrey Dante</li>
  • JP Fortes
  • 杰弗里·但丁
    $(“#输入搜索”)。自动完成({
    来源:功能(请求、响应){
    $.get('EmployeeSearchList.igx',{name:request.term},
    功能(数据){
    var html=“”;
    对于(变量i=0;i'+data[i]。label+'';
    }
    $(“ul”).append(html);
    });
    }
    });
    

    像这样的东西应该能奏效。您可能需要进一步深入查看
    数据
    对象,因此只需检查返回的内容,以确保在正确的数组中循环。

    没错,伙计,但仍然没有数据,只有加载的gif视图。如何在自动完成中填充此内容?脚本是否影响了$.get代码?用ajax代替get怎么样?哇!我为此疯狂@_@对不起,误读了问题!您是否已签出本教程:
    $("#input-search").autocomplete({
        source: function(request, response) {
            $.get('EmployeeSearchList.igx', { name: request.term }, 
            function(data) {
                var html = "";
                for(var i=0; i < data.length; i++){
                   html += '<li value="'+data[i].value+'">'+data[i].label+'</li>';
                }
                $("ul").append(html);
            });
        }
    });