Skip to main content

Uncaught TypeError: Illegal invocation

Sometimes you got error Uncaught TypeError: Illegal invocation while submit a form using ajax in javascript. There could be any reason for this error but in my case I have found this error because I did not pass the the processData: false, to $.ajax() settings.

  • Solution for error uncaught TypeError: Illegal invocation

    Add processData: false, to ajax settings

    <script>
    $('#form').on('submit', function(e){
        e.preventDefault();
        var formData = new FormData($(this)[0]);
        $.ajax({
            type: "POST",
            dataType: "json",
            processData: false,
            url: "/add-record",
            data: formData,
            success: function(data){
                return 'response';
                console.log(data);
            }
        }); 
    });
    </script>

    Add processData: false, as key/value pair to ajax settings to avoid the error Uncaught TypeError: Illegal invocation while calling ajax on form submit.

  • Back to code snippet queries related javascript