Caio Tarifa Caio Tarifa - 9 months ago 871
Javascript Question

Jquery and HTML FormData returns "Uncaught TypeError: Illegal invocation"

I'm using this script to upload my image files:

$('.uploader input:file').on('change', function() {
$this = $(this);


$.each($this[0].files, function(key, file) {
$('.files').append('<li>' + + '</li>');

data = new FormData();
data.append(, file);

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 to your options object fixes the error, but I'm not sure if it fixes the problem.