3

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?

1 Answer 1

2

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" }, ... ]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.