0

jqueryUIのオートコンプリートを使用しようとしています。応答を警告すると、次のようになります。([ { "id": "test", "label": "test", "value": "test" } ]);

しかし、結果をマップしようとすると、ドロップダウンの結果は空になります。これが私のコードです:

<script>
$(function() {
    function log( message ) {
        $( "<div/>" ).text( message ).prependTo( "#log" );
        $( "#log" ).scrollTop( 0 );
    }

    $( "#city" ).autocomplete({
        source: function( request, response ) {
            $.ajax({
                url: "http://localhost/jQuery/development-bundle/demos/autocomplete/search3.php",
                jsonp: "jsonp_callback",
                data: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 12,
                    name_startsWith: request.term
                },
                success: function( data ) {
                    alert(data);
                    response( $.map( data, function( item ) {
                        return {
                            label: item.label,
                            value: item.value
                        }
                    }));
                }
            });
        },
        minLength: 2,
        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" );
        }
    });
});
</script>

サーバーサイドスクリプトは次のコードを使用します。

echo $_GET['jsonp_callback'] . '(' . $data . ');';

とにかくありがとう

4

1 に答える 1

1

この行を使用してください

url: "http://ws.geonames.org/searchJSON?jsonp_callback=?",

およびデータ型も

dataType: 'jsonp',

それ以外の

url: "http://ws.geonames.org/searchJSON",
于 2012-04-16T10:16:20.700 に答える