Sending multipart/formdata with jQuery.ajax

Starting with Safari 5/Firefox 4, it’s easiest to use the FormData class: var data = new FormData(); jQuery.each(jQuery(‘#file’)[0].files, function(i, file) { data.append(‘file-‘+i, file); }); So now you have a FormData object, ready to be sent along with the XMLHttpRequest. jQuery.ajax({ url: ‘php/upload.php’, data: data, cache: false, contentType: false, processData: false, method: ‘POST’, type: ‘POST’, // … Read more

What does enctype=’multipart/form-data’ mean?

When you make a POST request, you have to encode the data that forms the body of the request in some way. HTML forms provide three methods of encoding. application/x-www-form-urlencoded (the default) multipart/form-data text/plain Work was being done on adding application/json, but that has been abandoned. (Other encodings are possible with HTTP requests generated using … Read more