こんにちは私はレールapiとangularJsのプロジェクトを作って、次のエラーが見つかりました。レール付きAngularjs API残り400(悪いリクエスト)
angular.js:11821 POST http://localhost:3000/people 400(不正なリクエスト)
そして私はなぜ見つけることができませんでした。
以下のコード。それが似ている場合
Railsのコントローラ
# POST /people
def create
@person = Person.new(person_params)
if @person.save
render json: @person, status: :created, location: @person
else
render json: @person.errors, status: :unprocessable_entity
end
end
AngularJS
$scope.SendData = function() {
// use $.param jQuery function to serialize data from JSON
var data = $.param({
name: $scope.name,
age: $scope.age,
gender:$scope.gender,
lonlat:$scope.lonlat
});
var config = {
headers : {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
$http.post('http://localhost:3000/people', data, config)
.then(function (data, status, headers, config) {
$scope.PostDataResponse = data;
})
.catch(function (data, status, header, config) {
$scope.ResponseDetails = "Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + header +
"<hr />config: " + config;
});
};
Htmlの
関連ログを投稿してください。 400のエラーコードは、サーバーに不正な形式で要求を送信すると、悪い要求を意味します。ブラウザのコンソールログとRailsログで、リクエストに関する情報を確認します。 –
POST http:// localhost:3000/people 400(不正リクエスト) (匿名)@ angular.js:11821 n @ angular.js:11582 g @ angular.js:11292 (匿名)@ angular.js :16104 $ evalの@はangular.js:17378 $ angular.js @ダイジェスト:17191 $ angular.js @適用されます。angular.js @ 17486 (匿名):25177 のRf angular.js @:3487 D @ angular.js:3475私のクロムコンソールで –
"ステータス":400、 "エラー": "不良リクエスト"、 "例外": "#\ u003cActionController :: ParameterMissing:paramは が見つからないか値が空です:人\ u003e"、 "トレース" :{"アプリケーショントレース":{{"id":1、 "trace": "app/controllers /people_controller.rb:47:in' person_params '"}火かき棒ログ –