数据远程真正定义一个回调 [英] data-remote true defining a callback

查看:139
本文介绍了数据远程真正定义一个回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个,我想提出的数据远程=真选项形式。但我想有我的创建操作返回JSON,那么已经通过JavaScript代码已经在页面上存在处理。我可以设置一个回调内嵌的的form_for标记?

也有类似这样:

  =的form_for @foo,:远程=>如此,:成功=> my_js_stuff做| F |
 

解决方案

我不知道这是否是可能的,而不覆盖轨​​道形成帮手。但是你可以使用jQuery AJAX事件,并绑定到他们。例如:

  $('#形式的注册表单)。ajaxError(函数(事件,要求设置){
 //做一些错误的东西
})

$('#形式的注册表单)绑定(AJAX:成功',功能(EVT,数据,身份,XHR){
//做成功的一些东西
})
 

I have a form that I would like to submit with the data-remote=true option. But I want to have my create action return json, then have that handled by javascript that already exists on the page. Can I set a callback inline with the form_for tag?

Something similar to this:

=form_for @foo,:remote => true, :success => "my_js_stuff" do |f|

解决方案

I'm not sure if it will be possible without overriding rails form helper. But you can use jquery ajax events and bind to them. For example:

$('form#sign-up-form').ajaxError(function(event, request, settings) {
 //do some stuff on error
})

$('form#sign-up-form').bind('ajax:success', function(evt, data, status, xhr){
//do some stuff on success
})

这篇关于数据远程真正定义一个回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆