Hello guys,
I am trying to store image using AJAX call in laravel. While I am requesting it is giving me an error of JQuery. I want to store my image on S3 bucket. I have done:
HTML code:
<input type="file" class="" name="image" id="image{{$sub->id}}" accept="image/*">
<button type="button" class="btn btn-success updateVal" id="update" value="{{$sub->id}}">Update</button>
JS code:
$('.updateVal').click(function() {
var id = $(this).val();
var parent_id = "{{$productAttributeValue->id}}";
var valueType = 'sub';
var _token = $('input[name="_token"]').val();
var subValue = $('#value'+id).val();
var subValImage = $('#image'+id).val();
var theFormFile = $('#image'+id).get()[0].files[0];
console.log(theFormFile);
var data = {_token: _token, mainVlaue: parent_id, valueType: valueType, value: subValue, image: theFormFile, id:id, _method: 'PUT'};
console.log(data);
$.ajax({
url: '/admin/update/sub-product-attribute-value/'+id,
type: 'PUT',
data: data,
dataType: 'json',
success:function(response)
{
if(response.code == 200) {
window.location.reload();
} else {
}
//
}, error: function(response) {
alert(response);
}
});
});
I got one solution that give this -> processData: false, into AJAX request. But it is not passing data in request at laravel side. Can anyone knows another solution.
Thanks in advance..