I'm submitting my form using ajax in laravel
Output:
{"message":"The given data was invalid.","errors":{"name":["The name field is required."],"image":["The image field is required."]}}
View:
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<h2 class="card-inside-title">Name</h2>
<div class="form-line focused">
</div>
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-6">
<div class="form-group">
<h2 class="card-inside-title">Image</h2>
<div class="form-line focused">
</div>
</div>
</div>
</div>
<button class="btn btn-info add_button btn-xs p-3 hide" type="button"><i class="material-icons">add</i> Add</button>
</div>
Script:
$('#frmadd').submit(function(e) {
e.preventDefault();
var formData = new FormData($(this)[0]);
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: APP_URL+'/add',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response)
{
},
error: function(data)
{
}
});
});
via Chebli Mohamed