2014-09-02 24 views
0

我試圖用jQuery來發送POST請求到Rails控制器,這是POST請求:ERROR變量Errno :: ECONNABORTED:一個已建立的連接被軟件中止你

$(document).ready(
    function() { 
     $("#LogIn").submit(function() { 
      var myemail = $('input[name=Email]').val(); 
      var mypassword = $('input[name=Password]').val(); 
      var myObj = { 
       "user": { 
        "email": myemail, 
        "password": mypassword 
       } 
      }; 
      $.ajax({ 
       url: "localhost:3000/user/HendelLogIn", 
       type: "POST", 
       data: myObj, 
       dataType: "application/json" 
       success: function(data) { 
        alert(data); 
       } 
      }); 
     }); 
    } 
); 

</script> 

,你可以看到POST請求是到以下地址:本地主機:3000 /用戶/ HendelLogIn

這是HendelLogIn方法:

def HendelLogIn 
    email = params[:user][:email] 
    password = params[:user][:password] 
    @User = User.authenticate(email, password) 
    if @User 
    redirect_to :controller => "user", :action => "profile", :id => @User.id 
end 

,正如你可以看到這個動作redirect_to的下列行動:

def profile 
    @User = User.find(params[:id]) 
    if @User 
    respond_to do |format| 
    format.json {render :json => @User } 
    end 
    end 
end 

呈現回JSON響應到jQuery的職位,但在這個過程中我有在軌控制檯以下錯誤:

Redirected to localhost:3000/user/1/profile 
Completed 302 Found in 140ms (ActiveRecord: 1.0ms) 
[2014-09-02 14:12:03] ERROR Errno::ECONNABORTED: An established connection was aborted by the software in your 

主機。

c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:396:in `write' 
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:396:in `<<' 
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:396:in `_write_data' 
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:368:in `send_body_string' 
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:249:in `send_body' 
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:152:in `send_response' 
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:110:in `run' 
    c:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' 
+0

檢查網絡連接 – Milind 2014-09-02 12:12:36

+0

您不應該使用大寫字母('HendelLogIn')命名方法 – MikDiet 2014-09-02 12:19:22

+0

您認爲這是問題嗎?關於互聯網連接的 – user3410606 2014-09-02 12:22:14

回答

0

您的javascript和樣式表標籤可能存在問題。

刪除application.html.erb中標題部分的所有標記。

希望這樣可以解決您的問題。

相關問題