3

I am passing form-data via AJAX:

var data = new FormData();
data.append('username', username);
data.append('company', company);

$.ajax({
   url: 'path to service',
   type: 'POST',
   enctype: 'multipart/form-data',
   async: true,
   contentType: 'multipart/form-data',
   processData: false,
   data: data,
   cache: false,
   success: function(data){

   },
   error: function(error){

   }
});

But I get an error:

the request was rejected because no multipart boundary was found

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
user544079
  • 16,109
  • 42
  • 115
  • 171
  • 1
    possible duplicate of [How to send FormData objects with Ajax-requests in jQuery?](http://stackoverflow.com/questions/6974684/how-to-send-formdata-objects-with-ajax-requests-in-jquery) – Djizeus May 30 '14 at 17:24

1 Answers1

8

You should set the contentType to false, which will force jQuery to generate the content-type header, including the mandatory multipart boundary.

EDIT: just realised it was already answered in: How to send FormData objects with Ajax-requests in jQuery?

Community
  • 1
  • 1
Djizeus
  • 4,161
  • 1
  • 24
  • 42