jQuery和HTML FORMDATA返回"未捕获的类型错误:非法调用" [英] Jquery and HTML FormData returns "Uncaught TypeError: Illegal invocation"
本文介绍了jQuery和HTML FORMDATA返回"未捕获的类型错误:非法调用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用这个脚本上传我的图片文件: http://jsfiddle.net/eHmSr/
I'm using this script to upload my image files: http://jsfiddle.net/eHmSr/
$('.uploader input:file').on('change', function() {
$this = $(this);
$('.alert').remove();
$.each($this[0].files, function(key, file) {
$('.files').append('<li>' + file.name + '</li>');
data = new FormData();
data.append(file.name, file);
$.ajax({
url: $('.uploader').attr('action'),
type: 'POST',
dataType: 'json',
data: data
});
});
});
但是,当我点击上传按钮,JavaScript控制台返回此错误:
But when I click in upload button, the JavaScript console returns this error:
Uncaught TypeError: Illegal invocation
您能帮我吗?
推荐答案
jQuery的处理数据
属性和值转换成字符串。
jQuery processes the data
attribute and converts the values into strings.
添加过程数据:假
您的选择对象修复的错误,但我不知道它是否解决了这个问题。
Adding processData: false
to your options object fixes the error, but I'm not sure if it fixes the problem.
演示: http://jsfiddle.net/eHmSr/1/
Demo: http://jsfiddle.net/eHmSr/1/
这篇关于jQuery和HTML FORMDATA返回&QUOT;未捕获的类型错误:非法调用&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文