【发布时间】:2011-01-27 20:15:32
【问题描述】:
使用respond_to 时,我的 AJAX 调用仅在 HTML 响应不存在时调用 javascript 响应。
我有以下 javascript 用于提交就地编辑操作:
$(".eip").editable("/surveys", {
name : 'survey[name]',
select : true,
event : 'edit',
submit : 'Save',
cancel : 'cancel',
cssclass : "editable",
onblur : 'ignore',
onedit : function() { $(".eip_desc").hide(); },
onreset : function() { $(".eip_desc").show(); },
onsubmit : function() { $(".eip_desc").show(); }
});
然后我有以下调查控制器方法:
class SurveysController < ApplicationController
def create
@survey = Survey.new(params[:survey])
if @survey.save
respond_to do |format|
format.html { redirect_to surveys_path, :notice => "Survey created!" }
format.js
end
else
render :action => :new
end
end
end
如果我删除了format.html 行,那么format.js 会做出应有的响应。但是,如果我将format.html 留在其中,那么当我通过该editable javascript 位提交时,整个页面都会呈现。
我正在为此应用运行 Rails 3.0.3。
【问题讨论】:
-
正确的操作可能是 UPDATE 吗?您正在编辑资源吗?
标签: javascript ruby-on-rails respond-to