您好,请我使用typeahead插件使用JSON,我想获得图像和名称,但我得到未定义
$('input.typeahead').typeahead({
source: function(query, process){
$.ajax({
url : "http://localhost/centrix/tasks/getRelatedAccount",
type : 'POST',
data : 'query='+query,
dataType : 'JSON',
async : true,
success : function(data){
return process(data.contact_name);
}
});
},
highlighter: function(data){
html = '<div class="typeahead">';
html += '<div class="media"><a class="pull-left" href="#"><img class="img-circle img-xs" src='+data.contact_name+' /></a>';
html += '<div class="media-body">';
html += '<p class="media-heading">'+data.contact_name+'</p>';
html += '</div>';
html += '</div>';
return html;
}
});
发布于 2018-06-15 08:44:47
您正在发出jQuery AJAX POST请求来获取.json (假设端点返回.json数据),为什么不直接使用他们的解决方案之一呢?
更不用说你似乎没有以预期的方式使用这个库。
这是他们最基本的例子之一:
https://twitter.github.io/typeahead.js/examples/#the-basics
祝好运!
https://stackoverflow.com/questions/50867589
复制相似问题