Unfortunately, it’s not as easy as setting the data
attribute to the FormData
instance; jQuery runs anything that isn’t a string through jQuery.param()
to serialize the objects keys into key1=a&key2=b
etc; running FormData
through this doesn’t end too nicely.
However one of jQuery.ajax()
‘s many options is processData
, which allows you to turn off this behaviour by setting it’s value to false
. So, to use FormData
with jQuery.ajax()
it’s as simple as:
var formData = new FormData($('form')[0]); // Create an arbitrary FormData instance jQuery.ajax('/endpoint.php', { processData: false, contentType: false, data: formData });
Read full article from Sending FormData with jQuery.ajax() | Matt
No comments:
Post a Comment