簡體   English   中英

如果存在format.html,則response_to無法與format.js一起使用

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM