【问题标题】:How to load data in textbox from ajax using twitter bootstrap?如何使用 twitter bootstrap 从 ajax 加载文本框中的数据?
【发布时间】:2013-04-08 08:41:10
【问题描述】:

我尝试使用 bootstrap typeahead 函数在文本框中加载简单的 ajax 返回值。如果我通过警报检查它,它会返回数据,但是当我在文本框中输入时,什么都没有。我尝试在没有 ajax 的情况下将数据直接发送到 source:['albama','utah'],它工作正常。我已经包含了所有相关文件。我

<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>

【问题讨论】:

    标签: jquery twitter-bootstrap bootstrap-typeahead


    【解决方案1】:

    试试这样的

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-16
      • 2012-12-31
      • 1970-01-01
      • 2012-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-08
      相关资源
      最近更新 更多