“ajax:成功”被召唤两次

我正在使用jquery_ujs发送简单的post请求。 我将回调函数绑定到“ajax:success”事件。 但是,对于每个成功的post,都会调用此回调两次。

我知道这与其他问题类似,但是我检查了我的源代码并且它似乎没有加载jquery_ujs.js文件两次(正如许多响应所建议的那样)。

$(".new_item").bind("ajax:success", function(xhr, data, status) { /* this is called twice for each call!*/ } 

任何人有任何指针? 谢谢!

其中一件事正在发生。

你有多个元素与.new_item类

 alert($(".new_item").length); 

你发送了两次ajax请求

 alert("Sending Request"); $.ajax(... 

或者你绑定事件两次

 alert("Binding Event"); $(".new_item").bind("ajax:success", function(xhr, data, status) { 

注意:如果您使用的是现代浏览器,请使用console.log()替换警报