I tried to upload images using AJax,Jquery,Laravel. Here I tried with so many solutions still I am getting 419 error and in some cases getting 500 internal error.
Code I tried is
<form method="POST" id="needs" novalidate enctype="multipart/form-data">
{{csrf_field()}}
<input name="image1" id="image1" type="file" class="form-control" required="" />
<br>
<input type="file" name="image2" id="image2" class="form-control" required/>
<br>
<input type="file" name="image3" id="image3" class="form-control" required/>
<br>
<input type="file" name="image4" id="image4" class="form-control" required/>
<br>
<input type="file" name="image5" id="image5" class="form-control" required />
<br>
<button type="button" id="upload_image" name="upload_image" class="btn btn-lg btn-success" onclick="image_up();">Upload</button>
</form>
Jquery:
function image_up()
{
alert("Uploading start");
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: "{{route('collage.store')}}",
type: 'POST',
data : new FormData($(this)[0]),
dataType: "json",
cache : false,
processData: false,
success: function () {
alert('form was submitted');
}
});
}
Route:
Route::post('/', 'CollagePrimController@post')->name('collage.store');
Please anyone help me to fix this issue. Thanks in advance