Rails 3.0和JQuery表单回调未触发
我有一个表单,我把它放在一个页面的IFrame中。IFrame显示一个rails表单,其中包含一个要保存的按钮和一个取消链接 我使用以下代码添加iFrame:Rails 3.0和JQuery表单回调未触发,jquery,ruby-on-rails-3,Jquery,Ruby On Rails 3,我有一个表单,我把它放在一个页面的IFrame中。IFrame显示一个rails表单,其中包含一个要保存的按钮和一个取消链接 我使用以下代码添加iFrame: $('#saveAreaForm').contents().find('#cancel_save').click(function() { $('#saveAreaForm').remove(); }); $('#saveAreaForm').conte
$('#saveAreaForm').contents().find('#cancel_save').click(function() {
$('#saveAreaForm').remove();
});
$('#saveAreaForm').contents().find('#create_area_form').bind("ajax:failure", function(xhr, status, error) {alert("failure!");});
$('#saveAreaForm').contents().find('#create_area_form').bind('ajax:success', function(xhr, status, error) {alert("failure!");});
删除表单的链接可以正常工作,但回调永远不会触发
我在控制台中看到控制器代码被触发,但我无法接收成功或失败
这是表格代码(HAML):
这是控制器的功能:
# POST /areas
# POST /areas.xml
def create
@area = Area.new(params[:area])
respond_to do |format|
if @area.save
format.html { redirect_to(@area, :notice => 'Area was successfully created.') }
format.xml { render :xml => @area, :status => :created, :location => @area }
else
format.html { render :action => "new" }
format.xml { render :xml => @area.errors, :status => :unprocessable_entity }
format.json { render :json => @area.errors, :status => :unprocessable_entity }
end
end
end
有什么明显的地方我忽略了吗?问题是bind语句可能是在创建DOM对象之前调用的。我使用live而不是bind解决了这个问题。我已经研究了routes文件,我认为那里的所有设置都是正确的(我知道我触发了正确的控制器方法)。
# POST /areas
# POST /areas.xml
def create
@area = Area.new(params[:area])
respond_to do |format|
if @area.save
format.html { redirect_to(@area, :notice => 'Area was successfully created.') }
format.xml { render :xml => @area, :status => :created, :location => @area }
else
format.html { render :action => "new" }
format.xml { render :xml => @area.errors, :status => :unprocessable_entity }
format.json { render :json => @area.errors, :status => :unprocessable_entity }
end
end
end