简体   繁体   English

多个带有预输入处理程序的文本字段未执行AJAX调用?

[英]More than one text field with typeahead handler not executing AJAX call?

Before I ask my question I'll state some of the tools I'm using: 在提出问题之前,我将陈述一下我正在使用的一些工具:

I have the typeahead to function wonderfully with only one textfield. 我只有一个文本字段才能很好地发挥作用。 However, when I add another text field and try to hook up the typehead handler to the second one, the second one fails to execute the AJAX call and I'm pulling my hair out trying to figure out what the problem is. 但是,当我添加另一个文本字段并尝试将Typehead处理程序连接到第二个文本字段时,第二个文本处理程序将无法执行AJAX调用,并且我将头发拉出来试图找出问题所在。

HTML Code: HTML代码:

<div id = "tester" class="well">
<input id = "test" class="typeahead" type="text" placeholder="Search" data-provide="typeahead" autocomplete="off" spellcheck="false" dir="auto" style="position: relative; vertical-align: top;">
</div>

<div id = "tester2" class="well">
<input id = "test2" class="typeahead" type="text" placeholder="Search" data-provide="typeahead" autocomplete="off" spellcheck="false" dir="auto" style="position: relative; vertical-align: top;">
</div>

Javascript: 使用Javascript:

<script src="assets/js/jquery-1.11.0.js"></script>
<script src="assets/js/bootstrap.js"></script>

<script>

$(function(){
$('.typeahead').typeahead({
    source: function(typeahead, query){
        $.ajax({
            url: 'my_controller',
            type: 'POST',
            data: 'query=' + query,
            dataType: 'JSON',
            async: true,
            success: function(data){
                typeahead.process(data);
            }

        });
    }
});
});

</script>

The AJAX call is failing to even execute with the second typeahead where as the first one works fine. AJAX调用甚至无法通过第二次预输入执行,因为第二次预输入工作正常。 I don't know what I'm missing. 我不知道我在想什么。 I'm even selecting the input by class name. 我什至按类名选择输入。

I would greatly appreciate any help or guidance. 我将不胜感激任何帮助或指导。

Here is a jsfiddle: http://jsfiddle.net/pK6g5/ 这是一个jsfiddle: http : //jsfiddle.net/pK6g5/

Thank you. 谢谢。

your "modified bootstrap-typeahead.js" library use $.browser which is not in jQuery since 1.9. 您的“修改过的bootstrap-typeahead.js”库使用$.browser ,它从1.9开始不在jQuery中。 To keep it you can add Jquery Migrate . 要保留它,您可以添加Jquery Migrate

I just added the library to your fiddle and it seems to work: FIDDLE 我刚刚将库添加到您的小提琴中,它似乎可以正常工作: FIDDLE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM