0

I'm really hoping someone can help!

I have looked through every possible answer on Stack Overflow to this. I create the form data

var formData = new FormData();

var uploadedFile = hiddenFileElement[0].files[0]

var inputValues = form.serializeArray();

$.each(inputValues, function(key, input) {
     formData.append(input.name, input.value);
});

// add file
formData.append('file', uploadedFile);

I then prepare an ajax request and send the post data to a example.php file.

 /**
     * http://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax
     */
$.ajax({
   url: url,
   data: formData,
   processData: false,
   contentType: false,
   type: 'POST'

}).done(function (response) {
....

When I receive this server side, I var dump $_FILE and $_POST are empty. I know the inputs exist when it builds the form data object. I even used the FormDataUnsafe example in another thread to confirm those values are there when posting. My header looks like this:

Request Payload

My content type is UTF-8 plain-text.

Content-Type:text/plain;charset=UTF-8

Shouldn't JQuery be changing this?

Also are their any server related configuration I should be thinking about?

Help would be appreciated, thanks.

Cust Ex
  • 15
  • 2
  • Have you verified in your browser that data is being sent? In Firefox I use Firebug to inspect the actual post data. – Jason K Aug 18 '15 at 16:02
  • I have found that the CSRF token from another file was malforming the request using $.ajaxPrefilter. I am going to alter this so that I append the csrf token to FormData. – Cust Ex Aug 19 '15 at 11:15

0 Answers0