0

I am using html5 to allow allow drag and drop of files , and submit form data along with files in a multipart/form-data request with the mozilla FormData() api ( there is a append() function for a FormData object and I append values and files with it ). I use the jQuery.ajax() and set the data to the FormData object I created and set the processData flag to false, and contentType to "multipart/form-data" , with a beforeSend handler call jqXHR.setReqeustHeader("Conetent-Type", "multipart/form-data") again . But in the firebug I can see that request header is still having Content-Type: text/html .

It seems $.ajax() ignore my content type specification . Has anyone else successfually using jQuery.ajax() to work with FormData api of html5 ?

I know that I can make my own XMLHttpReqeust without help of jquery , and it works too . But I like a unified framework such as jquery.

dan_l
  • 1,692
  • 2
  • 23
  • 40
  • You can set `contentType: 'multipart/form-data'` with jQuery, IIRC. – Blender Dec 08 '11 at 04:38
  • I did both the contentType: "multipart/form-data" , and the beforeSend event where I call jgXHR.setRequestHeader("Content-Type", "multipart/form-data") . – dan_l Dec 08 '11 at 05:03
  • I found another post that solves the problem . http://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax – dan_l Dec 09 '11 at 05:39

1 Answers1

1

You should set contentType to false instead of real content type. Also set processData to false. Here is more details.

Vladimir Prudnikov
  • 6,974
  • 4
  • 48
  • 57