Rails + jquery:ERROR Errno :: ECONNRESET:由peer重置连接

时间:2013-12-16 10:43:28

标签: jquery ruby-on-rails errno

在我的Rails 4应用程序(ruby 2.0)中使用jquery发送AJAX请求时出现问题。

错误是:

ERROR Errno::ECONNRESET: Connection reset by peer

JS:

$("#user_main_filter_all").click(function() 
{
    $("#spinner").show();
$.ajax({
        dataType: "json",
  cache: false,
        url: '/finder/main_filter_changed/all',
  timeout: 5000,
        beforeSend : function(xhr) { xhr.setRequestHeader("Accept", "application/json") },
  error: function(XMLHttpRequest, errorTextStatus, error) { alert("Failed to submit : "+ errorTextStatus+" ;"+error); },
  success: function(data) 
        {                    
            $("#user_main_filter_all").css("background-color","#000000");
            $("#user_main_filter_stored").css("background-color","transparent");

            $("#spinner").hide();

            refresh_user_data();
    }
});
});

Ruby(称为方法):

  def main_filter_changed
    session[:user_page] = nil

    if !params[:id].blank?
      session[:user_main_filter] = params[:id]
    else
      session[:user_main_filter] = 'all'
    end

    respond_to do |format|
      format.json  { render :json => nil }     
    end

  end

该方法被调用,之后,我在我的日志中:

Processing by FinderController#main_filter_changed as JSON
  Parameters: {"_"=>"1387190059468", "id"=>"all"}
Completed 200 OK in 3ms (Views: 0.2ms | ActiveRecord: 0.5ms)
[2013-12-16 11:34:20] ERROR Errno::ECONNRESET: Connection reset by peer

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:80:in `eof?'
    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:80:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

我的第一个问题是protect_from_forgery和csrf_token的问题......但我刚刚测试并评论了行protect_from_forgery并且我有相同的行为。

因此,服务器错误会提供javascript警告:

error: function(XMLHttpRequest, errorTextStatus, error) { alert("Failed to submit : "+ errorTextStatus+" ;"+error); },

被称为显示的警告框(但不是errorTextStatus)。

0 个答案:

没有答案