Submitting a file with jQuery.ajax gives TypeError
I was having the same problem with similar code. There's a severe dearth of information about this error, so since the OP didn't elaborate:
With some debugging I realised the error was being thrown by the ajax call in the depths of jquery, not the actual append.Turns out I'd forgotten to add processData: false, contentType: false
to the ajax request; Doing so fixed the problem.
It works fine when you add the the following to the ajax object:
contentType: false,processData: false,
So it should look like:
$.ajax({ url:'elements/save_elements', data:formdata, type:'POST', contentType: false, processData: false,});
Adding these parameter to ajax solve the problem
$.ajax({ url: 'upload_ajax.php', type: 'POST', data: formData, contentType: false, processData: false,