jQuery Autocomplete fetch and parse data source with custom function, except not
- by Ben Dauphinee
So, I am working with the jQuery Autocomplete function, and am trying to write a custom data parser. Not sure what I am doing incorrectly, but it throws an error on trying to call the autocompleteSourceParse function, saying that req is not set.
setURL("ajax/clients/ac");
function autocompleteSourceParse(req, add){
var suggestions = [];
$.getJSON(getURL()+"/"+req, function(data){
$.each(data, function(i, val){
suggestions.push(val.name);
});
add(suggestions);
});
return(suggestions);
}
$("#company").autocomplete({
source: autocompleteSourceParse(req, add),
minLength: 2
});