jQuery.ajax 文件上传

发布于 2025-01-06 20:10:56 字数 117 浏览 2 评论 0原文

我们有一个带有文件类型输入的模态表单。我们希望当用户单击“保存”时将文件上传到服务器。我们不想真正刷新页面,而只是关闭模式。

我们可以通过 $.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

意中人 2025-01-13 20:10:56

$.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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文