【发布时间】:2016-04-17 21:29:54
【问题描述】:
我搜索了很多,但无法找到我的错误。当我刚开始使用 JS 时,这可能很容易。使用:Rails 4
我有一个带有表单的模式,我想在成功(或不成功)执行 ajax 调用后做一些事情。现在只是关闭模式。
模态(这确实有效,所以我可以编辑东西):
.modal.fade{ id: attribute.id, role: 'dialog', tabindex:'-1' }
.modal-dialog{ role: 'document'}
.modal-content
.modal-header
%button{ type: 'button', class: 'close', 'data-dismiss' => "modal" }
%span ×
%h4.modal-title= attribute.name
= form_for attribute, remote: true, html: { class: 'form-inline', id: 'edit_form' } do |f|
.modal-body
.form-group
= f.label :name, 'Name', class: 'form-label', style: 'width: 150px'
= f.text_field :name, class: 'form-control', style: 'width:200px;margin-right: 35px'
.modal-footer
%button{ type: "button", class: "btn btn-default pull-left", 'data-dismiss' => "modal" }
Close
= f.submit 'Create', class: 'btn btn-primary pull-right'
我的 JS 文件(别笑):
$(document).ready( function($) {
console.log('ready'); # this I *can* see in the console
$('#edit_form').bind("ajax:success", function() {
console.log('great success') # this I *can't* see in the console.
});
});
控制器(另一个有趣的事实:模式是在不同控制器的视图中触发的,而不是我实际尝试更改的模式):
respond_to do |format|
format.js {}
end
所以最后我想捕捉“错误”和“成功”回调并用它做某事(这是我想先弄清楚自己)。我在这里做错了什么?
非常感谢您的帮助 - 非常感谢!
【问题讨论】:
标签: javascript ruby-on-rails ajax twitter-bootstrap ruby-on-rails-4