gpt4 book ai didi

jQuery .autocomplete 不过滤

转载 作者:行者123 更新时间:2023-12-01 02:44:51 27 4
gpt4 key购买 nike

我在 jQuery 和 JSON 方面完全是新手,花了几个小时但仍然没有解决问题

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

来自 serverURI.asp 的 JSON

["A. ASRUNADI", "A. MURSYID", "A. RIFANI", "A.Z MAKMUR IS", "ABBAS", "ABDI  IRWANTO"]

我的jquery

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

但是...当我将 JSON 作为 var 放入 jquery 时它的工作原理...同时我已经在我的 html 元标记中使用 utf-8

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

我的 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

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

最佳答案

如果您不想在服务器端进行过滤,则应该对源发出 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
});
});
});

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

关于jQuery .autocomplete 不过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13955393/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com