怎么在jquery里面用 $.ajax 上传文件。
AJAX 在一些低版本的 IE 上不支持文件上传,可以考虑使用 iframe 上传文件!
参考:https://github.com/malsup/form
通过这种方式,文件域被提交到一个 iframe 里!
10 回答11.2k 阅读
5 回答4.9k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
用 FormData,一个例子:
I'm pretty late for this but I was looking for an ajax based image uploading solution and the answer I was looking for was kinda scattered throughout this post. The solution I settled on involved the FormData object. I assembled a basic form of the code I put together. You can see it demonstrates how to add a custom field to the form with fd.append() as well as how to handle response data when the ajax request is done.
Upload html: