javascript - JQuery UI Autocomplete with PHP file source


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:

.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
$(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 " + :
                "Nothing selected, input was " + this.value );

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




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

An Array of Strings:

[ "Choice1", "Choice2" ]


An Array of Objects with label and value properties:

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

People are also looking for solutions to the problem: php - Codeigniter upload library get thumb file name


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.