我一直在寻找几天,但找不到修复.
$("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']
}
}));
}
});
}
});
Uncaught TypeError: Object has no method 'results' (in Chrome)
TypeError: this.options.messages.results is not a function (in Firefox)
错误指向jqueryui.js中的一行,在我的脚本中由“response()”调用.
解决方法:
非常古老的问题,但今天仍然具有相关性,因为它发生在我身上,我不确定接受的答案涵盖所有基础,或解释问题.
发生这种情况是因为自动完成插件要求您提供带有noresults的消息对象和结果属性,以告知它如何标记搜索结果.
noresults属性应该是一个字符串,在您猜对了,没有结果时显示.
那么results属性应该是一个接受count参数的方法,并返回一个字符串.
像这样的东西:
$("input").autocomplete({
source: function( request, response ){
... your $.ajax request stuff
},
messages: {
noresults: "No results",
results: function(count){
return count + (count == 0 ? ' result' : ' results');
}
}
});
调用响应(数据)是可能的;根本不需要设置这些属性.但在我的情况下,一位同事提供了一个消息对象,但是将noresults和results属性都设置为字符串值,因此错误:
this.options.messages.results is not a function
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。