使用PHP文件源的JQuery UI自动完成

使用PHP文件源的JQuery UI自动完成

问题描述:

I am trying to use JQueryUI autocomplete, with data coming from a remote source (another php script). Below is the example given in the demos on the JQueryUI website:

<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>

My question is about the PHP script "search.php". Should this script simply return an array?

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

 &lt; style&gt; 
.ui-autocomplete-loading {background:white url('images / ui-anim_basic_16x16。  gif')右中心不重复;  } 
&lt; / style&gt; 
&lt; script&gt; 
 $(function(){
 function log(message){
 $(“&lt; div /&gt;”)。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 选中,输入为“+ this.value”; 
} 
}); 
}); 
&lt; / script&gt; 
  code>  pre> 
 
 

我的问题是 关于PHP脚本“search.php”。 这个脚本应该只返回一个数组吗? p> div>

The response should be a JSON formatted array in either of these two formats:

An Array of Strings:

[ "Choice1", "Choice2" ]

OR

An Array of Objects with label and value properties:

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