开发者

jquery autocomplete issue

开发者 https://www.devze.com 2023-02-26 17:26 出处:网络
JS $( \"#ethnicbg\" ).autocomplete({ source: function( request, response ) { $.ajax({ url: \'ethnic/\', type: \'POST\',

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    = 开发者_Python百科$this->url->get();
$arr    = get_data(); // returns [{"title":"White","value":"White"}]
echo json_encode($arr);

It returns the data, the problem is somewhere at success: function, just before the response($.map.... I putted console.log('TEST') dnt seem to go there at all, or alert anything what am I doing wrong?

Solved

dataType: "jsonp", should be dataType: "json", If anything can someone explain the difference between json, jsonp ? in this case so it helps me and other people who might come accross?


Solved

dataType: "jsonp", should be dataType: "json", If anything can someone explain the difference between json, jsonp ? in this case so it helps me and other people who might come accross?

0

精彩评论

暂无评论...
验证码 换一张
取 消