gpt4 book ai didi

javascript - 如何合并ajax请求和ajax响应?

转载 作者:行者123 更新时间:2023-11-28 08:20:27 25 4
gpt4 key购买 nike

What i want ?

实际上我正在寻找类似上图的东西。

我试图添加带有ajax响应的ajax请求,我怎么失败了,请帮助我。

源代码:

$(function () {
var availableTags = [

"gmail.com", "hotmail.com", "outlook.com",


];

function customFilter(array, terms) {
arrayOfTerms = terms.split("@");
var term = $.map(arrayOfTerms, function (tm) {
return $.ui.autocomplete.escapeRegex(tm);
}).join('|');
var matcher = new RegExp("\\b" + term, "i");
return $.grep(array, function (value) {
return matcher.test(value.label || value.value || value);
});
};

$("#tags").autocomplete({



multiple: true,
mustMatch: false


,source: function (request, response) {

// delegate back to autocomplete, but extract the last term
response(customFilter(
availableTags, request.term));
},
});


});

我有这个..

enter image description here

最佳答案

以下内容将覆盖源数组以添加请求项:

$("#tags").autocomplete({
source: function (request, response) {
if( request.term.indexOf("@") == -1 ){//char "@" not in request

var arr = $.map(availableTags, function (tag, i) {
return (request.term + "@" + tag);
});

response(arr);
}
}
});

FIDDLE

关于javascript - 如何合并ajax请求和ajax响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23035191/

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