微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Rails jQuery UJS回调没有触发

我正在尝试触发ajax:远程链接的成功回调.我在Rails 3.0.8和 jquery-rails 1.0.11上.我运行了jquery生成器来安装 javascripts. jquery和jquery_uj都包含在我的认值中,我可以验证它们是否包含在页面中.

这是我的javascript:

jQuery(function($) {
  $("#deactivate")
    .bind("ajax:success",function() {
      alert("HELLO");
    })
    .bind("ajax:error",function() {
      alert("GOODBYE");
    }
  );
});

链接

= link_to 'Deactivate',activate_patient_path(patient),:id => 'deactivate',:class => "button button-red",:remote => true

激活动作:

def activate
    patient = Patient.find(params[:id])
    patient.do_not_call = !patient.do_not_call
    if patient.save
      render :nothing => true
    else
      render :status => 500,:nothing => true
    end
end

ajax调用似乎工作正常.触发操作,我可以看到数据库中的更改.但是,没有触发ajax回调.我不能让他们中的任何一个工作.我可以获得其他事件,例如点击,以便完美地工作.

如果我在Firebug中调试rails_ujs,我会看到以下代码从Rails ajax块运行:

success: function(data,status,xhr) {
  element.trigger('ajax:success',[data,xhr]);
}

我很难过.有任何想法吗?

解决方法

确保在rails.js之后你没有再次包含jquery.js …我遇到了类似的问题,其中jquery.js被包含两次,并且rails.js包含在其中.

原文地址:https://www.jb51.cc/jquery/176037.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐