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
,
...
});
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:
- [Solved] JS Ajax uploads an error “uncaught type error: illegal invocation”
- [Solved] Jquery ajax “Uncaught TypeError: Illegal invocation”
- Postman reported an error unsupported media type [How to Solve]
- [Solved] Content type ‘application/x-www-form-urlencoded;charset=UTF-8’ not supported
- Problem solving of req.body undefined
- Convert to IE9 below $. Ajax to return “no transport” across domains
- [Solved] Java.io.EOFException: No content to map to Obje…
- When parsing background JSON data with Ajax: unexpected token o in JSON at position 1
- Ajax submitting datagram in firebox_ ERROR_ DOCUMENT_ NOT_ Cached error
- When using bootstrap modal box, uncaught typeerror: $(…). Modal is not a function