【问题标题】:jquery autocomplete issuejquery自动完成问题
【发布时间】:2011-08-08 17:22:12
【问题描述】:

JS

$( "#ethnicbg" ).autocomplete({
    source: function( request, response ) {
        $.ajax({
            url: 'ethnic/',
            type: 'POST',
            dataType: "jsonp",
            data: {
                q: request.term
            },
            success: function( data ) {
                response( $.map( data, function( item ) {
                    return {
                        label: item.title,
                        value: item.value
                    }
                }));
            }
        });
    },
    minLength: 1,
    select: function( event, ui ) {
        // log( ui.item ?
            // "Selected: " + ui.item.label :
            // "Nothing selected, input was " + this.value);
    },
    open: function() {
        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
    },
    close: function() {
        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
    }
});

PHP

header('Content-type: application/json');
$url    = $this->url->get();
$arr    = get_data(); // returns [{"title":"White","value":"White"}]
echo json_encode($arr);

它返回数据,问题出在成功的地方:函数, 就在response($.map.... 之前,我输入了console.log('TEST') dnt 似乎根本没有去那里,或者提醒我做错了什么?

已解决

dataType: "jsonp", 应该是dataType: "json", 如果有人可以解释 json, jsonp 之间的区别吗?在这种情况下,它可以帮助我和其他可能遇到的人吗?

【问题讨论】:

标签: ajax jquery-ui jquery autocomplete


【解决方案1】:

解决了

dataType: "jsonp", 应该是 dataType: "json", 如果有人能解释一下 json, jsonp 之间的区别吗?在这种情况下,它可以帮助我和其他可能遇到的人吗?

【讨论】:

    猜你喜欢
    • 2010-12-04
    • 2013-01-22
    • 2016-05-31
    • 2011-10-08
    • 2011-11-16
    • 2017-06-19
    • 2011-08-11
    • 1970-01-01
    相关资源
    最近更新 更多