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要求を行うことができることを確認します。あなたはそれがレール見ることができるログから
が同様に私たちのバックエンドのコードを表示してください。 – born4new
体内に追加しました。バックエンドログに – Kahsn
があります。これは、railsアプリケーションがhtmlまたはjsonをレンダリングしているかどうかを確認できます。ログを確認または投稿できますか? – rick