如何使用Twitter Bootstrap从Ajax加载文本框中的数据? [英] How to load data in textbox from ajax using twitter bootstrap?

查看:99
本文介绍了如何使用Twitter Bootstrap从Ajax加载文本框中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用bootstrap typeahead函数在文本框中加载简单的ajax返回值.如果我通过警报检查它返回了数据,但是当我在文本框中键入内容时,什么也没有.我尝试了直接数据到source:['albama','utah']而没有ajax,它工作正常.我已包含所有相关文件.我

I tried to load simple ajax return value in textbox using bootstrap typeahead function. If I check it by alert it return data but When I type in textbox there is nothing. I tried with direct data to source:['albama','utah'] without ajax it works fine. I have included all related files. I

<input type ="text" id ="subjects" data-provide="typeahead" />

<script>
$(document).ready(function() {


$('#subjects').typeahead

                ({
                        source: $.ajax({


                                          url: "./test/test.php",
                                           type: "POST",
                                          data: "search=" + $('#subjects').attr('value'),
                                        success: function(data)
                                        {

                                var subjects = ['Albamsa', 'Washington', 'New York', 'Arlington', 'New Jersey'];                                          return subjects;

                                        }
                                })



                });

});
</script>

推荐答案

尝试类似的方法

$('#subjects').typeahead({

    source: function (query, process) {
        return $.getJSON(
            './test/test.php',
            { query: query },
            function (data) {
                return process(data);
            });
    }

});

还可以在脚本中使用json_encode函数获取返回值

Also use json_encode function in your script for returned values

这篇关于如何使用Twitter Bootstrap从Ajax加载文本框中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆