加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

autocomplete – twitter bootstrap 3.0 typahead ajax示例

发布时间:2020-12-18 00:12:37 所属栏目:安全 来源:网络整理
导读:有很多类型的头像ajax示例在那里为bootstrap 2,例如这里这里 twitter bootstrap typeahead ajax example。 但是我使用引导3,我找不到一个完整的例子,而只是一堆不完整的信息片段与其他网站的链接,例如这里Where is the typeahead javascript module in b
有很多类型的头像ajax示例在那里为bootstrap 2,例如这里这里 twitter bootstrap typeahead ajax example。

但是我使用引导3,我找不到一个完整的例子,而只是一堆不完整的信息片段与其他网站的链接,例如这里Where is the typeahead javascript module in bootstrap 3 RC 1?

有人可以在每次用户更改输入时,通过ajax从服务器加载数据,然后再发布一个关于如何使用引导程序3使用typeahead的完整工作示例。

解决方法

使用bootstrap3 -a打头像,我使用以下代码:
<input id="typeahead-input" type="text" data-provide="typeahead" />

<script type="text/javascript">
jQuery(document).ready(function() {
    $('#typeahead-input').typeahead({
        source: function (query,process) {
            return $.get('search?q=' + query,function (data) {
                return process(data.search_results);
            });
        }
    });
})
</script>

后端在搜索GET端点提供搜索服务,在q参数中接收查询,并返回格式为{‘search_results’:[‘resultA’,’resultB’,…]}的JSON。 search_resultsarray的元素显示在前导输入中。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读