Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在文本框中输入时未触发Twitter引导Typeahead_Jquery_Bootstrap Typeahead - Fatal编程技术网

Jquery 在文本框中输入时未触发Twitter引导Typeahead

Jquery 在文本框中输入时未触发Twitter引导Typeahead,jquery,bootstrap-typeahead,Jquery,Bootstrap Typeahead,我试图在我的代码中实现bootstrap Typeahead,但由于某种原因,当我在文本框中输入任何文本时,什么都不会发生(我试图使用ajax调用获取数据,并期望代码在输入的每个文本上运行) 代码 Javascript $('#searchQuery').typeahead({ minLength: 3, source: function (query, process) { $.ajax({

我试图在我的代码中实现bootstrap Typeahead,但由于某种原因,当我在文本框中输入任何文本时,什么都不会发生(我试图使用ajax调用获取数据,并期望代码在输入的每个文本上运行)

代码

Javascript

    $('#searchQuery').typeahead({    
        minLength: 3,          
        source: function (query, process) {
            $.ajax({
            type: 'GET',
            url: xxx,
            datatype: 'json',
            cache: false,
            data: { searchText: xxx },
            success: function (aData) {
                process(aData);
            }
        });
    }});
我希望每次在文本框中输入字符时,代码都会调用此javascript,但什么也没发生

任何帮助都将不胜感激。

试试这个方法

$("#searchQuery").typeahead({
  source: function(query, process) {
    return $.ajax({
      url: "XXX",
      type: "GET",
       data: { searchText: xxx },
      success: function(result) {
        return process(result);  // this returns an array checked with console
      }
    });
  }
});

你的解决方案似乎有效,但你能解释到底是什么让它有效吗?除了去掉minLength参数外,我没有做任何更改。只要看清楚我的帖子,我提到了return…..你错过了那一个…不,你得到了啊。。