jQuery.ajax 文件上传
我们有一个带有文件类型输入的模态表单。我们希望当用户单击“保存”时将文件上传到服务器。我们不想真正刷新页面,而只是关闭模式。
我们可以通过 $.ajax 上传文件吗?否则,有哪些工具可用于在后台上传文件?
We have a modal form with an input of type file. We want to upload the file to the server when the user clicks 'Save'. We don't want to actually refresh the page, but simply close the modal.
Can we upload a file via $.ajax? Otherwise, what tools are available for uploading files behind the scenes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$.ajax()
可以工作,但您最好指定 POST。请参阅此处的答案:使用 jQuery.ajax 发送 multipart/formdata
另外,这jquery插件支持文件上传:
http://jquery.malsup.com/form/
$.ajax()
will work, but you'll do best to specify a POST. See the answer here:Sending multipart/formdata with jQuery.ajax
Also, this jquery plugin supports file uploads:
http://jquery.malsup.com/form/