jQuery .autocomplete不会过滤

aka*_*uts 2 jquery jquery-ui asp-classic jquery-autocomplete jquery-ui-autocomplete

我是jQuery和JSON的新手,花了好几个小时但仍然没有解决问题

来自服务器的JSON有效,通过jsonlit.com检查但它仍然显示所有数据(未过滤).

来自serverURI.asp的JSON

["A. ASRUNADI", "A. MURSYID", "A. RIFANI", "A.Z MAKMUR IS", "ABBAS", "ABDI  IRWANTO"]
Run Code Online (Sandbox Code Playgroud)

我的jquery

$("#keyword").autocomplete({
    source: function(request, response){
       $.getJSON("serverURI.asp", function(data){
           var source = data
           response(source);
       });
    }
});
Run Code Online (Sandbox Code Playgroud)

但....当我把JSON作为var in jquery时它的作品...同时我已经在我的html元标记中使用了utf-8

$(function() {
    var availableTags = ["A. ASRUNADI", "A. MURSYID", "A. RIFANI", "A.Z MAKMUR IS", "ABBAS", "ABDI  IRWANTO"];
    $("#keyword").autocomplete({
        source: availableTags
    });
});
Run Code Online (Sandbox Code Playgroud)

我的ASP(经典)生成JSON如下

    dim strResultEMP
strResultEMP = "["
for strEmpCount = 0  to strTotalCountEmp
    strEmpObj = split(strEmpSplit(strEmpCount), "$$$")
        if strEmpCount < strTotalCountEmp then
            strResultEMP = strResultEMP & """" & ucase(strEmpObj(1)) & """" & ", "
        else
        strResultEMP = strResultEMP & """" & ucase(strEmpObj(1)) & """" & ""
        end if

next
strResultEMP = strResultEMP & "]" 
response.write strResultEMP
Run Code Online (Sandbox Code Playgroud)

仅供参考,我使用JSON2.asp和JSON UTIL,但它仍然相同.调试和捕获服务器响应我使用Firebug.

And*_*ker 6

如果您不想在服务器端进行过滤,则应该为源发出AJAX请求,然后将该源传递给自动完成小部件:

$(function () {
    /* Make the AJAX request once for the source array: */
    $.getJSON("serverURI.asp", function (data) {
        /* Initialize the widget with the data we got back: */
        $("#keyword").autocomplete({
            source: data
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

请记住,如果您拥有大量数据,这可能会降低用户浏览器的速度.如果你有很多(> 500)项,我强烈建议你在服务器上进行过滤.