I'm trying to make a post request using ajax. I keep getting a 419 error. Carefully checking code and all, i have the headers set for csrf but somehow the request doesn't contain this token which results in the 419 error. The meta is set in the section of the page yet somehow not included in the request.
Anyone encountered this before and how do i fix it?
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: "{{ route('payment-methods.store') }}",
type: "POST",
data: formData,
contentType: false,
processData: false,
success: function(response) {
if(response.success) {
Swal.fire({
icon: 'success',
title: response.msg,
timer: 1500
}).then(function() {
location.reload();
});
} else {
Swal.fire({
icon: 'error',
title: response.msg,
timer: 1500
});
}
},
error: function(error) {
console.log(error);
},
complete: function() {
$("#addPaymentMethodBtn").text('Add Payment Method');
$("#addPaymentMethodBtn").attr("disabled", false);
}
});