简体   繁体   English

如果存在format.html,则response_to无法与format.js一起使用

[英]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.

相关问题 respond_to 做 |格式| format.js 在 Rails 6.1.3 中不起作用 - respond_to do |format| format.js not working in rails 6.1.3 使用response_to format.js替换Rails上textarea的内容 - using respond_to format.js to replace the content of a textarea on rails 为什么在使用 AJAX 时,respond_to 执行的是 format.html 而不是 format.json? - Why is respond_to executing format.html instead of format.json when using AJAX? 在format.html和format.js之间显示Rails3 Flash消息? - Display Rails3 Flash messages between format.html and format.js? response_to块中的Format.js无法以条件格式运行 - Format.js in respond_to block doesn't work in an conditional format Rails:make(link_to“示例”,“#”,远程:true)绕过(respond_to…format.js) - Rails: make (link_to “example”, “#”, remote: true) bypass (respond_to … format.js) Rails 3.1:使用&#39;respond_to ... format.js&#39;而不使用&#39;page&#39;变量的新方法 - Rails 3.1: The new way to use 'respond_to … format.js' without the 'page' variable 使用Javascript操作响应format.html - Respond to format.html with Javascript action response_to js“未知格式” - respond_to js “unknown format” 使用response_来做| format | 在将照片收藏在模态内之后,format.js在模态内显示消息? - using respond_to do |format| format.js to show a message inside of a modal after photo is favorited inside a modal?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM