使用jQuery自动完成仅查询源一次?

时间:2018-12-21 14:00:31

标签: jquery jquery-ui-autocomplete

是否可以使用jquery自动完成功能一次查询source属性?因为在键入的每个键上,它都会触发ajax调用:

$("#tagitTipos").tagit({
            autocomplete: {
                delay: 0, minLength: 1, source: function (request, response) {

                    $.ajax({
                        url: '/Controller/Method/',
                        type: 'GET',
                        dataType: 'json',
                        async: false,
                        cache: false,
                        data: {Termo: term},
                        success: function (dados) {
                            let data = JSON.parse(JSON.stringify(dados));
                            response($.map(data, function (item) {
                                return {
                                    label: item,
                                    value: item
                                };
                            }));
                        },
                        failure: function (response) {
                            return [];
                        },
                        error: function (response) {
                            return [];
                        }
                    });
                }
            },
        });

0 个答案:

没有答案