@kazehaya 422 is natural response code for invalid data and the errors say exactly the same. Next thing, you're passing {_token: "...", data: "serialized data"}, so you don't have firstname, lastname, 'email` keys in your submited data.
Mar 27, 2015
12
Level 4
422 (Unprocessable Entity error when submitting form with ajax
het there im trying to send a form with ajax but im getting this error.
422 (Unprocessable Entity)
<script>
$(function() {
$( "#productForm" ).submit(function( e ) {
e.preventDefault();
var token = $('input[name=_token]').val();
var dataString = $(this).serialize();
$.ajax({
type: "POST",
url: "contact-product",
data: {_token: token, data: dataString },
success: function (form) {
$("#contact-success").modal('show');
}
});
});
});
</script>
This is my datastring:
_method=PUT&_token=GfEc7e07jT4chnDUHFJzXFK7viLQAZ4n3neeZ13d&firstname=John&email=johndoe%40mail.com&lastname=Doe&phone=425345345&questions=no+info&custom=&product=testproduct+R+4024+TC
jquery.js:8625 POST http://example.local/contact-product 422 (Unprocessable Entity)
Here is the response in my network tap which i think is causing the trouble:
{"firstname":["The firstname field is required."],"lastname":["The lastname field is required."],"email":["The email field is required."]}
Level 53
Please or to participate in this conversation.