jQuery Autocomplete Mysql PHP

前端 未结 4 1876
暗喜
暗喜 2020-12-10 07:56

Hi could some one please take a look at this and let me know where I\'m going wrong. I am trying to get jQuery UI autocomplete to work. this is my code: This is search.php

4条回答
  •  难免孤独
    2020-12-10 08:36

    Have a look at jquery ui autocomplete documentation. The JSON you are returning does not match what the autocomplete is looking for. The object you return must have properties named label or value (or both).

    You can try the following options:

    Option 1: Change returned JSON

    Change the JSON being returned to include the label/value properties such as:

    [{"label":"Sin City"}]
    

    From the examples it also seems to use the id property. I believe the above is the minimum requirement for the autocomplete to display a list of values. I think you can also return an array of strings and it will render it in exactly the same way as the above.

    [ "Sin City", "Etc" ]
        
    

    Option 2 : Change private _render function

    Change the private _renderItem function for the autocomplete to use your custom properties as shown in this autocomplete example (untested):

    $( "#project" ).autocomplete({
        source: "./search.php",
        minLength: 3    
    })
    .data( "autocomplete" )._renderItem = function( ul, item ) {
        return $( "
  • " ) .data( "item.autocomplete", item ) .append( item.Title ) .appendTo( ul ); };

    This is a bit more flexible but much uglier imho.

提交回复
热议问题