如何将ajax请求与ajax响应合并?

时间:2014-04-12 19:36:34

标签: javascript jquery ajax

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

1 个答案:

答案 0 :(得分:0)

以下内容会覆盖源数组以添加请求术语:

$("#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