Reputation: 1
When I trigger submitForm an error appears
500 (Internal Server Error) {message: 'Request failed with status code 500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE', config: {…}, request: XMLHttpRequest, …}
this is my ajax code
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: _this.apiUrl,
method: 'GET',
success: function(data) {
_this.libary = JSON.parse(data);
},
error: function(error) {
console.log(error);
}
});
this is my submitForm code
submitForm(event, id) {
event.preventDefault();
const _this = this;
var actionUrl = ! this.editStatus ? this.actionUrl : this.actionUrl+'/'+id;
axios.post(actionUrl, new FormData($(event.target)[0])).then(response => {
$('#modal-default').modal('hide');
_this.table.ajax.reload();
});
}
does anyone know how to fix it?
Upvotes: 0
Views: 143
Reputation: 11
axios.post(actionUrl, new FormData($(event.target)[0])).then(response => {
The code don't have the headers as the same of the ajax.
Add the headers after the new FormData($(event.target)[0])
, it will be an object, like { header: {'X-CSRF-TOKEN': YOUR VALUE} }
Upvotes: 0