2

我正在尝试使用 JQueryUI 自动完成,数据来自远程源(另一个 php 脚本)。以下是 JQueryUI 网站上的演示中给出的示例:

<style>
.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
</style>
<script>
$(function() {
    function log( message ) {
        $( "<div/>" ).text( message ).prependTo( "#log" );
        $( "#log" ).scrollTop( 0 );
    }

    $( "#birds" ).autocomplete({
        source: "search.php",
        minLength: 2,
        select: function( event, ui ) {
            log( ui.item ?
                "Selected: " + ui.item.value + " aka " + ui.item.id :
                "Nothing selected, input was " + this.value );
        }
    });
});
</script>

我的问题是关于 PHP 脚本“search.php”。这个脚本应该简单地返回一个数组吗?

4

1 回答 1

1

响应应该是以下两种格式之一的 JSON 格式数组:

字符串数组:

[ "Choice1", "Choice2" ]

或者

具有标签和值属性的对象数组:

[ { label: "Choice1", value: "value1" }, ... ]

于 2012-07-09T23:47:01.207 回答