Rails:如何抓住ajax的成功
Rails: How to catch ajax success
我在谷歌上搜索了很多,但都找不到我的错误。因为我刚开始使用JS,所以这可能很容易。使用:Rails 4
我有一个带有表单的模态,我想在成功(或不成功)完成ajax调用后做一些事情。现在只是关闭模态。
modal(这确实有效,所以我可以编辑东西):
.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
所以最后,我想抓住"错误"answers"成功"的回调,并用它做点什么(这是我首先想弄清楚的)。我在这里做错了什么?
非常感谢你的帮助,真的很感激!
根据您可能想要尝试的类似问题的答案:
$('#edit_form').on("ajax:success", ...
// ^-- instead of .bind
我想您也有一个最新的jQuery版本,所以尝试一下这个更改。
相关文章:
- 在ajax成功后,cluetip不适用于首次点击活动元素
- jQuery成功函数中的ajax成功函数
- jQuery触发器点击未从AJAX成功工作
- 如何使用jQuery可编辑插件检查ajax是否成功完成
- 执行ajax成功函数-jQUERY
- 如何从servlet获取数据到ajax成功
- ajax请求成功,但可以'我看不到我的数据
- 通过mvc中的ajax动作链接获取关于成功的响应头
- AJAX调用在chrome扩展中未成功
- Ajax正确发布表单,但不会返回成功数据
- Ajax没有't执行成功函数
- JQuery FullCalendar在从ajax成功调用rerenderEvents时遇到问题
- 为什么Jquery$.ajax在函数调用中触发所有statusCode,即使调用成功
- ajax成功地将数组中的数据放入表中各自的输入中
- 在成功时操作 AJAX 函数
- Backbone fetch中的Ajax在fetch调用退出后完成,因此fetch调用中没有成功/失败事件
- 如何从ajax成功回调函数中读取javascript变量
- 成功ajax:如果是200状态代码,则运行函数else另一个函数
- 当移动到“外部”版本时,“内部”成功 AJAX 中的“数据”变量应该更改为什么
- 如何获得变量警报(测试)从var测试成功ajax