我正在使用此脚本上传我的图像文件: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
    });
  });
});

But when I click in upload button, the JavaScript console returns this error:

Uncaught TypeError: Illegal invocation 

jQuery Error

Can you help me?

推荐答案

jQuery processes the data attribute and converts the values into strings.

Adding processData: false到你的选项对象修复了错误,但我不确定它是否修复了问题.

Demo: 100

Jquery相关问答推荐

使用 howler.js 中的变量播放多种声音

ASP.NET Core 6 jQuery 验证不起作用

如果选中了三个sibling ,则选中一个复选框

如何在jQuery中移动表格行?

如何 Select 具有特定文本的所有锚标记

jQuery.parseJSON 单引号与双引号

如何制作 AngularJS 指令来停止传播?

使用 jQuery 和 HTML 导出为 CSV

ASP .NET MVC 在每个字段级别禁用客户端验证

jQuery/JavaScript 碰撞检测

jQuery.extend 和 jQuery.fn.extend 的区别?

从附加元素获取 jQuery 对象的更简单方法

滚动 DIV 元素时如何防止页面滚动?

如何使用 jQuery 格式化电话号码

使用 Jquery 查找父 div 的 id

jQuery - 从元素内部 Select 元素

如何使用 jQuery Validation Plugin 以编程方式判断表单是否有效

使用javascript将HTML页面中的div下载为pdf

如何在jQuery中 Select 最后一个子元素?

Twitter Bootstrap 中的树