Uncaught typeerror: the solution of illegal invocation problem

An error occurred while uploading files using Ajax today. The data transmission method is completed by defining formData, and the submitted file object is also set as a dom object, but the request cannot be sent. F12 saw an error reported in the background: Uncaught TypeError: Illegal invocation. Baidu took a look and found a solution.

Solution: Add the following two parameters to the parameters of the ajax request:

$.ajax({
  ...,
  processData: false,
  contentType: false
  ...
});
processData

Type: Boolean

Default value: true. By default, the data passed in through the data option, if it is an object (technically speaking, as long as it is not a string), it will be processed and converted into a query string to match the default content type “application/x-www-form-urlencoded” “. If you want to send DOM tree information or other information that you don’t want to convert, please set it to false.

contentType

Type: String

Default value: ” application/x-www-form-urlencoded“. The type of content encoding when sending information to the server.

The default value is suitable for most situations. If you explicitly pass a content-type to $.ajax() then it must be sent to the server (even if there is no data to send).

 

Similar Posts: