首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Typeahead,我无法获取图像

Typeahead,我无法获取图像
EN

Stack Overflow用户
提问于 2018-06-15 08:16:21
回答 1查看 19关注 0票数 -2

您好,请我使用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;
  }
});
EN

回答 1

Stack Overflow用户

发布于 2018-06-15 08:44:47

您正在发出jQuery AJAX POST请求来获取.json (假设端点返回.json数据),为什么不直接使用他们的解决方案之一呢?

更不用说你似乎没有以预期的方式使用这个库。

这是他们最基本的例子之一:

https://twitter.github.io/typeahead.js/examples/#the-basics

祝好运!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50867589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档