I am trying to use jquery-ui to autocomplete in a search box. Since the search depends on the value of another form field, I use the callback for the source. I see that the request has been sent correctly. My remote script returns a simple array of strings, and at this point I cannot get it to work. A drop-down list is never built. Can someone tell me why? Here is the code:
$(document).ready(function(){
$("#species").autocomplete({
source: function( request, response ) {
$.ajax({
url: "/includes/species-ajax.cfm",
dataType: "jsonp",
data: {
term: request.term,
searchBy : function() {
var sb = $("#searchBy_hidden").val();
return (sb ? sb : 'common_name'); }
},
success: function( data ) {
response( $.map( data, function( item ) {
return {
label: item.name,
value: item.name
}
}));
}
});
}});
});
<input type="hidden" name="searchBy_hidden" id="searchBy_hidden" value="common_name" />
Enter the name of a species: <input type="textbox" size="30" id="species" />
Thank,
source
share