0

使用时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那里,那么当我通过那个editablejavascript 位提交时,整个页面都会呈现。

我正在为这个应用程序运行 Rails 3.0.3。

4

1 回答 1

1

来自文档

(字符串)方法:提交编辑内容时使用的方法。默认为 POST。您很可能想要使用 POST 或 PUT。PUT 方法与 Rails 兼容。

尝试传递一个方法:“put”

于 2011-01-27T20:45:28.303 回答