Skip to content Skip to sidebar Skip to footer

Using Jquery To Send Data From A Multipart/form-data Through Ajax

I've been working on this all day now, and I just can't get it working. I have basically got a simple ajax request using the jQuery library and I want to send the data which I post

Solution 1:

In order to make your multipart/formdata work, you must add some extra stuff in your ajax-request:

cache:false,
contentType:false,
processData:false,

You can easily create your data-field by doing this:

var uploadData = $("#uploadFile").prop("files")[0];
var newData = newFormData();

$.each($('#uploadFile').prop("files"), function(i, file) {
    newData.append('file-'+i, file);
});

in your ajax-request you'll have to set this:

data: newData

Post a Comment for "Using Jquery To Send Data From A Multipart/form-data Through Ajax"