javascript - jQuery UI autocomplete via ajax error: -
i've been searching days now, can't find fix.
here's code (shortened core functionality):
$("input").autocomplete({ source: function( request, response ){ $.ajax({ url: 'inc/ajax.php', type: "get", async: true, datatype: "json", data: { 'task' : 'tasktodo', 'squery' : request.term }, success: function( data ) { response($.map( data, function(item){ return { label : item['name'], value : item['name'] } })); } }); } });
the autocomplete work, i'm getting following error in browser's console:
uncaught typeerror: object has no method 'results' (in chrome) typeerror: this.options.messages.results not function (in firefox)
the error points line in jqueryui.js, called "response()"
in script.
even though error doesn't affect functionality i'd know why it's there.
very old question, still relevant today happened me , i'm not sure accepted answer covers bases, or explains problem.
this happens because autocomplete plugin expects provide messages object noresults , results properties telling how label search results.
the noresults property should string displayed when, you've guessed it, there no results.
the results property should method accepts count parameter, , returns string.
something this:
$("input").autocomplete({ source: function( request, response ){ ... $.ajax request stuff }, messages: { noresults: "no results", results: function(count){ return count + (count == 0 ? ' result' : ' results'); } } });
it's possible calling response(data);
avoids need set these properties @ all. in case, colleague had provided messages object, had set both noresults , results properties string values, hence error:
this.options.messages.results not function
Comments
Post a Comment