Ajax上传文件/照片时报错TypeError :Illegal invocation
问题
Ajax上传文件/照片时报错TypeError :Illegal invocation

解决
网上搜索问题,错误原因可能有以下几个,依次检查:
- 请求类型有误,如
post请求,但在后台设置的是get请求 - 参数有误。 如没有传参,或是参数对应不上去
File类型的参数被预先处理了- 参见Ajax原理
检查后发现应该时原因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)
}
})
})
参考
来源:https://segmentfault.com/a/1190000017832617
Ajax上传文件/照片时报错TypeError :Illegal invocation的更多相关文章
- jS Ajax 上传文件报错"Uncaught TypeError: Illegal invocation"
使用jquery ajax异步提交文件的时候报Uncaught TypeError :Illegal invocation错误,报错信息如图: 错误原因: jQuery Ajax 上传文件处理方式,使 ...
- 打包新版本上传到AppStore时报错 ERROR ITMS-90034:
今天打包新版本上传到AppStore时报错 ERROR ITMS-90034:"Missing or invalid signature.The bundle'com.xxx.xxx' at ...
- ajax上传文件及进度显示
之前在博文:原生ajax写法就提及过ajax2.0与1.0的差别是多了FormData和利用FormData文件上传(当然还有跨域,但不是本文的重点). 那么具体怎么样实现ajax上传文件呢? 一般来 ...
- django系列6--Ajax05 请求头ContentType, 使用Ajax上传文件
一.请求头ContentType ContentType指的是请求体的编码类型,常见的类型共有三种: 1.application/x-www-form-urlencoded 这应该是最常见的 POST ...
- ajax上传文件及nodeJS接收
ajax文件上传需要用到FormData 官方介绍 FormData对象用以将数据编译成键值对,以便用XMLHttpRequest来发送数据.其主要用于发送表单数据,但亦可用于发送带键数据(keyed ...
- jQuery ajax上传文件实例
jQuery ajax上传文件实例 <form id="form" enctype="multipart/form-data"><input ...
- IE8/9 JQuery.Ajax 上传文件无效
IE8/9 JQuery.Ajax 上传文件有两个限制: 使用 JQuery.Ajax 无法上传文件(因为无法使用 FormData,FormData 是 HTML5 的一个特性,IE8/9 不支持) ...
- springMVC+jsp+ajax上传文件
工作中遇到的小问题,做个笔记 实现springMVC + jsp + ajax 上传文件 HTML <body> <form id="myform" method ...
- Ajax上传文件进度条显示
要实现进度条的显示,就要知道两个参数,上传的大小和总文件的大小 html5提供了一个上传过程事件,在上传过程中不断触发,然后用已上传的大 小/总大小,计算上传的百分比,然后用这个百分比控制div框的显 ...
随机推荐
- REST与DDD
之前在为什么要使用MVC+REST+CQRS架构我曾经提出DDD是核心,REST是壳的观点,我想在这里详细谈谈我的思路. 今天正好看看到老外一篇博文Why REST is so important:按 ...
- [Maven] Project build error: 'packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging.
将<packaging>jar</packaging> 改为<packaging>pom</packaging>
- [LeetCode]14. Longest Common Prefix最长公共前缀
Write a function to find the longest common prefix string amongst an array of strings. If there is n ...
- Hibernate课程 初探一对多映射4-3 测试--信息查询
建立双向一对多关系,既可以由一方查询多方信息,同样可以由多方查询一方信息 demo: //查询学生所在班级 public static void showGidByStudent(){ Session ...
- <Android 基础(七)> DrawerLayout and NavigationView
介绍 DrawerLayout是Support Library包中实现了侧滑菜单效果的控件 android.support.v4.widget.DrawerLayout NavigationView是 ...
- StackTrack for debug
System.Diagnostics.Debug.WriteLine("Serial port. {0},{1}", this.GetType().FullName, new Sy ...
- [Maven]Eclipse集成遇到的问题
当maven项目导入到eclipse中后使用eclipse提供的maven命令执行任意一个出现 Exception in thread "main" java.lang.Unsup ...
- 《最牛B的Linux Shell命令》笔记
1.以sudo 运行上一条命令 sudo !! 大家应该都知sudo,不解释.但通常出现的情况是,敲完命令执行后报错才发现忘了sudo.如下: ➜ ~ cp ~/download/CentOS7-Ba ...
- ubuntu 安装 deb 软件包
参考链接地址 blog.csdn.net/kevinhg/article/details/5934462 sudo dpkg -i xxxx.deb 安装一个 Debian 软件包,如你手动下载的文件
- OpenGL学习 Following the Pipeline
Passing Data to the Vertex Shader Vertex Attributes At the start of the OpenGL pipeline,we use the i ...