Home > Article > Web Front-end > Ajax error when uploading files/photos TypeError: Illegal invocation solution
The content of this article is about the solution to the TypeError: Illegal invocation error when Ajax uploads files/photos. It has certain reference value. Friends in need can refer to it. I hope it will be useful to you. helped.
Problem
Ajax error when uploading files/photos TypeError: Illegal invocation
Solution
Online search problems, the error reasons may be as follows, check in order:
The request type is wrong, such as post request, But what is set in the background is that the get request
parameters are incorrect. If no parameters are passed, or the parameters do not correspond
File type parameters are pre-processed
After checking, it is found that it should Reason 3, so modify the code and set processData of $.ajax: false:
getToken().then( res => { console.log('获取七牛云token后上传图片') if(!res.hasOwnProperty('data')) return // 整理参数 var formData = new FormData() formData.append('token', res.data) formData.append('file', file) $.ajax({ url: '', type: 'POST', contentType: 'multipart/form-data', processData: false, // 增加这一行,不处理参数 data: formData, success: function (result) { console.log(result) } }) })
The above is the detailed content of Ajax error when uploading files/photos TypeError: Illegal invocation solution. For more information, please follow other related articles on the PHP Chinese website!