Ajax 如何在jquery autocomplete内部和外部访问jquery autocomplete的json响应?

Ajax 如何在jquery autocomplete内部和外部访问jquery autocomplete的json响应?,ajax,jquery-ui,jquery,Ajax,Jquery Ui,Jquery,以下是我得到的回复(它正在工作): 我想在下拉选择中显示每个类别和计数(*)。我没有立即的需要,但我可能会希望并在其他地方使用_core_product_id,在autocomplete字段之外 以下是我的自动完成jquery代码: .autocomplete({ source: function( request, response ) { $.getJSON( 'controllers/clean/ajax/search.php', { 'fi

以下是我得到的回复(它正在工作):

我想在下拉选择中显示每个类别和计数(*)。我没有立即的需要,但我可能会希望并在其他地方使用_core_product_id,在autocomplete字段之外

以下是我的自动完成jquery代码:

.autocomplete({
    source: function( request, response ) {
        $.getJSON( 'controllers/clean/ajax/search.php', {
            'fieldid_tableid_type' : this.element[0].id,
            'term': extractLast( request.term )
        //}, response(['red', 'green', 'blue']) );
        }, 
        response );
    },
    search: function() {
        // custom minLength
        var term = extractLast( this.value );
        if ( term.length < 2 ) {
            return false;
        }
    },
    focus: function() {
        // prevent value inserted on focus
        return false;
    },
    select: function( event, ui ) {
        var terms = split( this.value );
        // remove the current input
        terms.pop();
        // add the selected item
        terms.push( ui.item.value );
        // add placeholder to get the comma-and-space at the end
        terms.push( '' );
        this.value = terms.join( '| ' );
        return false;
    },
    delay: 750
});
.autocomplete({
来源:功能(请求、响应){
$.getJSON('controllers/clean/ajax/search.php'{
“fieldid\u tableid\u type”:此.element[0].id,
“术语”:extractLast(request.term)
//},回应([‘红色’、‘绿色’、‘蓝色’);
}, 
反应);
},
搜索:函数(){
//自定义最小长度
var项=提取时间(此值);
如果(术语长度<2){
返回false;
}
},
焦点:函数(){
//防止在焦点上插入值
返回false;
},
选择:功能(事件、用户界面){
var术语=分割(此值);
//删除当前输入
terms.pop();
//添加所选项目
术语推送(ui.item.value);
//添加占位符以在末尾获得逗号和空格
术语。推送(“”);
this.value=terms.join(“|”);
返回false;
},
延误:750
});
我不知道把“回应”放在哪里以及如何使用它。任何帮助都会很好。我知道还有其他问题(很多),但我还没有找到一个能解决我问题的。谢谢

我注意到jqueryui文档显示了在autocomplete内部使用的响应。然而,一些示例在其他地方显示了它(例如,就在源代码内部)。
jQuery UI文档:

响应是一个回调函数,您需要将远程加载的值传递给它

.autocomplete({
    source: function( request, response ) {
        response($.getJSON( 'controllers/clean/ajax/search.php', {
            'fieldid_tableid_type' : this.element[0].id,
            'term': extractLast( request.term )
            //}, response(['red', 'green', 'blue']) );
        }));
    },
    search: function() {
        // custom minLength
        var term = extractLast( this.value );
        if ( term.length < 2 ) {
            return false;
        }
    },
    focus: function() {
        // prevent value inserted on focus
        return false;
    },
    select: function( event, ui ) {
        var terms = split( this.value );
        // remove the current input
        terms.pop();
        // add the selected item
        terms.push( ui.item.value );
        // add placeholder to get the comma-and-space at the end
        terms.push( '' );
        this.value = terms.join( '| ' );
        return false;
    },
    delay: 750
});
.autocomplete({
来源:功能(请求、响应){
响应($.getJSON('controllers/clean/ajax/search.php'{
“fieldid\u tableid\u type”:此.element[0].id,
“术语”:extractLast(request.term)
//},回应([‘红色’、‘绿色’、‘蓝色’);
}));
},
搜索:函数(){
//自定义最小长度
var项=提取时间(此值);
如果(术语长度<2){
返回false;
}
},
焦点:函数(){
//防止在焦点上插入值
返回false;
},
选择:功能(事件、用户界面){
var术语=分割(此值);
//删除当前输入
terms.pop();
//添加所选项目
术语推送(ui.item.value);
//添加占位符以在末尾获得逗号和空格
术语。推送(“”);
this.value=terms.join(“|”);
返回false;
},
延误:750
});

谢谢你的提示。但我不明白json响应在哪里/如何解析并放到下拉列表中。你能解释一下吗?另外,我注意到你们把反应放在哪里和我把它放在哪里不同。但奇怪的是,我有另一个jquery自动完成,它使用相同的代码工作(但响应json的格式不同)。
.autocomplete({
    source: function( request, response ) {
        response($.getJSON( 'controllers/clean/ajax/search.php', {
            'fieldid_tableid_type' : this.element[0].id,
            'term': extractLast( request.term )
            //}, response(['red', 'green', 'blue']) );
        }));
    },
    search: function() {
        // custom minLength
        var term = extractLast( this.value );
        if ( term.length < 2 ) {
            return false;
        }
    },
    focus: function() {
        // prevent value inserted on focus
        return false;
    },
    select: function( event, ui ) {
        var terms = split( this.value );
        // remove the current input
        terms.pop();
        // add the selected item
        terms.push( ui.item.value );
        // add placeholder to get the comma-and-space at the end
        terms.push( '' );
        this.value = terms.join( '| ' );
        return false;
    },
    delay: 750
});