您好,欢迎访问一九零五行业门户网

Ajax上传文件/照片时报错TypeError :Illegal invocation的解决方法

本篇文章给大家带来的内容是关于ajax上传文件/照片时报错typeerror :illegal invocation的解决方法,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
问题
ajax上传文件/照片时报错typeerror :illegal invocation
解决
网上搜索问题,错误原因可能有以下几个,依次检查:
请求类型有误,如post请求,但在后台设置的是get请求
参数有误。 如没有传参,或是参数对应不上去
file类型的参数被预先处理了
检查后发现应该时原因3,故修改代码,设置$.ajax的processdata: 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)    }  })})
以上就是ajax上传文件/照片时报错typeerror :illegal invocation的解决方法的详细内容。
其它类似信息

推荐信息