2016-04-20 11 views
1

http put要求をレールバックエンドに発行するAngularクライアントがあります。http put要求により "net :: ERR_TOO_MANY_REDIRECTS"エラーが発生する

httpリクエストコードは、次のようなものです:私は渡している

$http({ 
     method: 'PUT', 
     url: 'http://localhost:3000/documents/' + $scope.document_id, 
     data: parameter 
    }).then(function successCallback(response) { 
      console.log(response); 
     }, function errorCallback(response) { 
      console.log("Error has occurred while getting user document data from the server"); 
     }); 

データは、以下のようなもので、それが有効なJSONです:

def update 
    respond_to do |format| 
     if @document.update(document_params) 
     format.html { redirect_to @document, notice: 'Document was successfully updated.' } 
     format.json { render :show, status: :ok, location: @document } 
     else 
     format.html { render :edit } 
     format.json { render json: @document.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

 var parameter = { 
    "document": { 
    "title": "I-129", 
    "data": JSON.stringify($scope.formData), 
    "user_id": 1 
    } 
} 

バックエンドのコードはfolloiwngのようなものです

サーバーログ取得中:

Started PUT "/documents/3" for ::1 at 2016-04-20 00:24:12 -0700 
Processing by DocumentsController#update as HTML 
    Parameters: {"document"=>{"title"=>"I-129", "data"=>"{\"text_id\":\"1111\",\"Date_id\":\"1111-11-11T08:00:00.000Z\",\"number_id\":11111222}", "user_id"=>0}, "id"=>"3"} 
Can't verify CSRF token authenticity 
    Document Load (0.1ms) SELECT "documents".* FROM "documents" WHERE "documents"."id" = ? LIMIT 1 [["id", 3]] 
    (0.0ms) begin transaction 
    Document Exists (0.1ms) SELECT 1 AS one FROM "documents" WHERE ("documents"."title" = 'I-129' AND "documents"."id" != 3) LIMIT 1 
    (0.0ms) commit transaction 
Redirected to http://localhost:3000/documents/3 
Completed 302 Found in 3ms (ActiveRecord: 0.3ms) 

私は置く要求を発行するたびに、私は

http://localhost:3000/documents/3ネットを言ってエラーを取得:: ERR_TOO_MANY_REDIRECTS

私はここで間違って何をしているのですか?そして私はURL('http://localhost:3000/documents/' + $scope.document_id)のPaw(郵便配達員と同様のプログラム)を通じてhttp put要求を行うことができることを確認します。あなたはそれがレール見ることができるログから

+0

が同様に私たちのバックエンドのコードを表示してください。 – born4new

+0

体内に追加しました。バックエンドログに – Kahsn

+0

があります。これは、railsアプリケーションがhtmlまたはjsonをレンダリングしているかどうかを確認できます。ログを確認または投稿できますか? – rick

答えて

2

Processing by DocumentsController#update as HTML 

HTML

としてコールを処理されたHTTP呼び出し

dataType: "json", 
headers: { 
    "Content-Type": 'application/json; charset=UTF-8', 
    "Accept" : "application/json" 
} 
+0

まだ運がありません。私に同じエラーを与える – Kahsn

+0

同じレールのログも? – rick

+0

まだ運がありません。私に同じエラーを与えます。 1つのthinig私は、ドキュメント内の私のuser_idがエラーの後に0に設定されていることに気付きました。ログは同じままです。 – Kahsn

0

にこれを追加してみてくださいはこれを試してみてください。

url: 'http://localhost:3000/documents/' + $scope.document_id + '.json' 

def update 
respond_to do |format| 
    if @document.update(document_params) 
    format.html { redirect_to @document, notice: 'Document was successfully updated.' } 
    format.json { render json: @document, status: :ok} 
    else 
    format.html { render :edit } 
    format.json { render json: @document.errors, status: :unprocessable_entity } 
    end 
end 

エンド

0

は、以下試してみてください。

dataType: "json", 
headers: { 
    'Accept': 'application/json', 
    'Content-Type': 'application/json' 
} 
関連する問題