jquery TypeError: Illegal invocation code example

Example 1: jquery ajax Uncaught TypeError: Illegal invocation

This error is due to formData which is json object and by default ajax requrie
values to be in string format and as a solution

1. you can either remove formData and pass the values separately 
	data: { username: document.getElementById('createUserForm').value }

2. you can set the dataType to be 'json' and processData to be false
    
	$.ajax({
        url : base_url+'index.php',
        type: 'POST',
        dataType: 'json',
        data: data,
        cache : false,
        processData: false
    })

Example 2: TypeError: Illegal invocation

Your datatype is not JSON, it’s a FormData. And for jQuery to send a FormData, it needs…
$.ajax({
    type: "POST",
    url: 'signin2.php',
    data: formData,
    processData: false, //add this
    contentType: false, //and this
})

Tags:

Html Example