function edit_expense(val){
var id = val;
var amount = $('#expense_amount_'+id).val();
var image = $('#img_file_'+id)[0].files[0];
$.ajax
({
type:'post',
url:'{{route('edit_expense')}}',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
processData: false,
contentType: false,
data: { "_token": "{{ csrf_token() }}",'id':id, 'amount': amount,'image': image },
success:function(data)
{
$('.revnue_updated').removeClass('d-none');
$(".revnue_updated").fadeOut(3000);
}
});
};
Here it is my code , I am getting csrf token mismatch after adding header also. I want to send image value in data but is showing csrf mismatch
2
Answers
You have multiple solutions for this problem.
and add this code to your ajax request
headers: {‘X-CSRF-Token’: $(‘meta[name="csrf-token"]’).attr(‘content’)}
In other hands you can add _token key to your ajax data and use {{csrf_token()}}
Use "Formdata()", below is the working code. I hope it helps.