Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Photoshopper's avatar

Uncaught TypeError: Illegal invocation in Ajax function

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();

    });
0 likes
4 replies
Photoshopper's avatar

The problem was that I missed a couple of ajax parameters

processData: false, contentType: false,

5 likes
swim360's avatar

@Photoshopper i am facing the same issue.

When i add processData: false, contentType: false,

I am unable to get data in controller with dd($request->all());

what can be issue here?

1 like
goodGuy's avatar

@swim360 Hi , I am having the same issue . I have added the parameters of processData: false, contentType: false. Ajax request is fired but I am getting empty request object in controller. Did you find the solution...?

UPDATE: I was using put method for request in ajax . When I updated it to post request, it started working..

Please or to participate in this conversation.