Having problems with jQuery UI Autocomplete

前端 未结 2 1081
面向向阳花
面向向阳花 2020-12-11 21:45

I\'m trying to use the new autocomplete function in jQuery UI, but I\'m having some problems.

I\'m able to retrieve data from the DB (I can see it in FireBug), but I

相关标签:
2条回答
  • 2020-12-11 22:06

    change your code to this (take it out of the click event handler):

    jQuery(function()
    {  
     jQuery('#brand_search').autocomplete({
            source: "http://mysite.com/wp-content/themes/storelocator/include/jquery.search.php?instance=brand",
                 minLength: 2,
                 delay: 50,
                 select: function(e, ui) {
                   alert(ui);
                  }         
     }); 
    });
    
    0 讨论(0)
  • 2020-12-11 22:28

    correct your php array with the following in order to get a correct json output for jquery-autocomplete:

    array_push
    (
       $brands,
       array
       (
          "label"  => $row['id'], 
          "value"  => html_entity_decode($row['name'], ENT_QUOTES, 'UTF-8') )
        );
    );
    

    because jquery autocomplete needs those json property names to run the autocomplete as specified on the documentation:

    The local data can be a simple Array of Strings, or it contains Objects for each item in the array, with either a label or value property or both. The label property is displayed in the suggestion menu.

    http://jqueryui.com/demos/autocomplete/#custom-data

    0 讨论(0)
提交回复
热议问题