[英]respond_to not working with format.js if format.html is present
When using respond_to
, my AJAX call only invokes the javascript response if the HTML response isn't present. 当使用
respond_to
,如果HTML的响应是不存在我的AJAX调用仅调用JavaScript响应。
I have the following javascript for submitting an edit-in-place action: 我有以下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(); }
});
Then I have the following Survey controller method: 然后,我有以下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
If I remove the format.html
line, then format.js
responds as it should. 如果我删除
format.html
线,然后format.js
响应,因为它应该。 But if I leave format.html
in there, then the whole page renders when I submit via that editable
javascript bit. 但是,如果我在其中保留
format.html
,那么当我通过该editable
javascript位提交时,整个页面都会呈现。
I'm running Rails 3.0.3 for this app. 我正在为此应用程序运行Rails 3.0.3。
from docs 来自docs
(String) method: Method to use when submitting edited content.
(字符串)方法:提交编辑内容时使用的方法。 Default is POST.
默认为POST。 You most likely want to use POST or PUT.
您最有可能要使用POST或PUT。 PUT method is compatible with Rails.
PUT方法与Rails兼容。
try to pass a method: "put" 尝试通过一种方法:“放”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.