【问题标题】:Conflict with twitter bloodhound with jQuery Validation plugin与 jQuery Validation 插件的 twitter Bloodhound 冲突
【发布时间】:2014-06-03 17:35:14
【问题描述】:

我正在使用 twitter 的 Bloodhound 建议引擎,以下是我正在使用的代码 sn-p

// instantiate the bloodhound suggestion engine
    var searchData = new Bloodhound({
        datumTokenizer: function (d) {
            return Bloodhound.tokenizers.whitespace(d.value);
        },
        queryTokenizer: Bloodhound.tokenizers.whitespace,        
        remote: {
            url: 'http://localhost/address/fetch?q=%Query' //Local URL           
        }
    });
    // initialize the bloodhound suggestion engine
    searchData.initialize();
    // instantiate the typeahead UI
    $('.typeahead').typeahead({        
        hint:false,
        highlight: true,
        minLength: 3
        }, {
        name:'search-data',
        displayKey: 'title',
        source: searchData.ttAdapter(),       
        templates: {            
            suggestion: Handlebars.compile('<p><strong>{{title}}</strong></p>')            
        }        
    });

Ajax 请求没有触发我在上面的代码 sn-p 中提到的内容,如果页面中不包含 jQuery Validation 插件,那么它工作正常。

如何克服这个问题?

更新:

我已经将 jQuery 验证插件从 1.7 升级到最新(1.12)然后它已经解决了这个问题,但我不知道这背后的原因是什么。如果有人知道确切原因,请发布答案。

【问题讨论】:

  • 使用jquery noConflict方法
  • 在发布问题之前尝试过,但没有解决问题。
  • AjAx 在哪里触发?我没有看到 ajax 关键字
  • remote: { url: 'http:://localhost/address/fetch?q=%Query' //本地 URL }

标签: jquery bloodhound jquery-context


【解决方案1】:

把他的代码放在 js 脚本的顶部

 jQuery.noConflict( true )
    //or
$.noConflict( true )

【讨论】:

    猜你喜欢
    • 2011-06-18
    • 1970-01-01
    • 2013-01-24
    • 2014-03-01
    • 2012-08-20
    • 1970-01-01
    相关资源
    最近更新 更多