私は現在、nodejsとangularjsを統合しています。私はbrowser.http 400の悪いrequset.Iでエラーが発生しました。フロントエンドエラーかバックエンドエラーか、解決策が必要ですか?angularjsのPOST 400の不正なリクエスト
register.htmlウィキペディアのList of HTTP status codesによる
<form class="register-form" name="myRegisterForm" ng-hide="login" ng-submit="register(user)" novalidate>
<input type="text" placeholder="Name" ng-model="user.name" name="username" minlength="5" maxlength="25"/>
<span style="color:red" class="error" ng-show="myRegisterForm.username.$error.minlength">Given Name should be above 5 letters.</span><br/>
<input type="text" placeholder="Phone number" ng-model="user.phone" name="phonenum"
minlength="10" maxlength="10" ng-pattern="/^[0-9-]*$/" required/>
<span style="color:red" ng-style="{'padding-top':'2px'}" ng-show="myRegisterForm.phonenum.$error.pattern">Please enter numbers only.</span>
<span style="color:red" class="error" ng-show="myRegisterForm.phonenum.$error.minlength">Phone number must be 10 digits .</span><br/>
<input type="text" name=email placeholder="Email address" ng-model="user.email"
ng-pattern="/^[a-z]+[a-z0-9._][email protected][a-z]+\.[a-z.]{2,5}$/" required/>
<span style="color:red" ng-style="{'padding-top':'2px'}" ng-show="myRegisterForm.email.$error.pattern">Please enter correct mail id</span><br/>
<input type="password" placeholder="Password" ng-model="user.password" minlength="8" maxlength="16"/>
<input type="password" placeholder="Confirm password" ng-model="user.cpassword" minlength="8" maxlength="16"/>
<span style="color:red" ng-style="{'padding-top':'2px'}" ng-show="user.password !== user.cpassword">Password is not match</span>
<textarea placeholder="Address" ng-model="user.address"></textarea>
<input type="submit" value="SIGN UP" />
<p class="message">Already registered? <p></form>
register.js
$scope.register = function (user) {
var data = {
"user" : {
"name": user.name,
"email": user.email,
"phone": "+91"+ user.phone,
"password": user.password,
"address": user.address
}
};
$http({
method: 'POST',
url: '',
headers: {'Content-Type': 'application/json'},
data: data
}).then(function successCallback(response) {
if (response.data) {
sharedServices.set(response.data);
$location.path('/login');
}
console.log(response);
}, function errorCallback(response) {
if (response) {
$scope.message = response.data;
}
});
};
に
を変更することで、この問題を解決し、あなたは私達がで行くことは何もないコードの男を投稿しなきゃ。 Welcome to SO – JordanHendrix
要求フォーマットが無効であるため、400 Bad Requestがサーバーから送信されます。 –
あなたは空白のURLを持っています、それは間違いありませんか? –