4
私はPOSTリクエストをしていますが、422レスポンス以外は取得できません。422エラーコードが表示されるのはなぜですか?
Vue.jsクライアントコード:
new Vue({
el: '#app',
data: {
form: {
companyName: '',
street: '',
city: '',
state: '',
zip: '',
contactName: '',
phone: '',
email: '',
numberOfOffices: 0,
numberOfEmployees: 0,
}
},
methods: {
register: function() {
this.$http.post('/office-depot-register', this.form).then(function (response) {
// success callback
console.log(response);
}, function (response) {
// error callback
console.log(response);
});
}
}
});
Laravelルート:
Route::post('/office-depot-register', ['uses' => '[email protected]', 'as' => 'office-depot-register']);
Laravelコントローラー:
public function register(Request $request)
{
$this->validate($request, [
'companyName' => 'required',
// ...
]);
// ...
}
私が知る限り、Laravelは422を送り返すと、要求が検証要件を満たしていないことを意味します。 (必要なフィールドが欠落している、他の検証の失敗など)http://stackoverflow.com/questions/34966690/error-422-unprocessable-entity-in-laravel-with-ajax 'companyName'は必須ですが、空の文字列、それはあなたの問題を引き起こしている可能性があります。 –
それはまさにそれです。あなたのコメントを回答として残して、私はそれを受け入れます。 – Donnie
うれしい私は助けることができた:) –