The problem was that I missed a couple of ajax parameters
processData: false, contentType: false,
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to send a form to my handler, but I get an error "Uncaught TypeError: Illegal invocation". When I try to send just a simple field value or text, everything works fine. What's wrong with "FormData"?
This is my ajax function
$('.image-upload').click(function(e){ var form = $('#myForm')[0]; var formData = new FormData(form);
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="token"]').attr('value')
}
});
$.ajax({
type: "post",
url: '{{ route('admin.articles.article.uploadImage', [$article]) }}',
data: {
form: formData
},
success: function (data) {
console.log(data);
},
error: function (data) {
console.log('Error:', data);
}
});
e.preventDefault();
});
Please or to participate in this conversation.