![](/img/trans.png)
[英]respond_to do |format| format.js not working in rails 6.1.3
[英]respond_to not working with format.js if format.html is present
当使用respond_to
,如果HTML的响应是不存在我的AJAX调用仅调用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(); }
});
然后,我有以下Survey Controller方法:
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。
来自docs
(字符串)方法:提交编辑内容时使用的方法。 默认为POST。 您最有可能要使用POST或PUT。 PUT方法与Rails兼容。
尝试通过一种方法:“放”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.