how to submit Form with AJAX Using enctype="multipart/form-data"?
Short answer: you don't. You cannot upload files via AJAX.
The usual workaround is to set the target of your form to a hidden iframe
and submit the form there, using a normal, non-AJAXy POST, to achieve the desired effect:
<form target="hiddenIframe" method="post" enctype="multipart/form-data">
...
</form>
<iframe name="hiddenIframe" id="hiddenIframe" style="display: none;" />
There's a jQuery plugin that uses this technique.
XMLHttpRequest level 2 added support for uploading files via AJAX, and its browser support is now good and growing. Here's a browser support overview.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With