简体   繁体   English

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

[英]how to merge ajax request with ajax response?

我想要的是 ?

Actually I am looking for something like above picture. 其实我正在寻找上面的图片。

I was trying to add ajax request with ajax response,How ever i have failed with that one please help me out. 我试图用ajax响应添加ajax请求,但是我失败了,请帮助我。

Source code: 源代码:

$(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));
    },
});


          });

I have got this one.. 我有这个。

在此处输入图片说明

The following overrides the source array to prepend the request term: 以下内容将覆盖源数组以添加请求项:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM