Autocomplete: remote source + categorized items

Autocomplete: remote source + categorized items

Hello, I need to combine a remote source (database) with the categorized items. I have tried different ways but I'm a newbie in this matter and I'm confused with the code. Could anybody help with a line of code or a suggestion  to understand this?, please:

<script>
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var self = this,
currentCategory = "";
$.each( items, function( index, item ) {
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
self._renderItem( ul, item );
});
}
});
</script>
<script>
$(function() {
var data = [
{ label: "anders", category: "" },
{ label: "andreas", category: "" },
{ label: "antal", category: "" },
{ label: "annhhx10", category: "Products" },
{ label: "annk K12", category: "Products" },
{ label: "annttop C13", category: "Products" },
{ label: "anders andersson", category: "People" },
{ label: "andreas andersson", category: "People" },
{ label: "andreas johnson", category: "People" }
];

$( "#search" ).catcomplete({
delay: 0,
source: data /////// >> (HERE: search.php, but































                                                what I need to replace
                                                above?)
});
});
</script>




And: Is there some modification to the original script SEARCH.PHP?
Thank you in advance.
Kind regards.