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/