如何使用 jQuery 表单插件取消文件上传
我正在使用 jQuery Forms 插件来执行异步文件上传。目前,用户中止上传的唯一方法是按浏览器上的“停止”按钮,这可能会导致其他 javascript 和 ajax 请求也停止。我想提供一个取消按钮,但我还没有找到任何方法来取消使用 API 进行的上传。
是否有一种内置方法,或者至少是我可以使用的强大黑客,可以在上传时取消上传?
I'm using the jQuery Forms plugin to do an asynchronous file upload. Currently, the only way for the user to abort that upload is to press the "Stop" button on their browser, which may cause other javascript and ajax requests to stop as well. I'd like to provide a cancel button, but I haven't found any way to cancel an upload as it is happening using the API.
Is there a built-in way, or at least a robust hack I can use, to cancel the upload as it occurs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ajaxForm
方法采用与 jQuery.ajax 相同的所有选项,因此可以捕获它在beforeSend
中生成的虚拟xhr
处理程序。xhr
有一个 abort 方法可以中止文件上传:The
ajaxForm
method takes all the same options that jQuery.ajax takes, so it is possible to capture the dummyxhr
that it produces in abeforeSend
handler. Thexhr
has an abort method that aborts the file upload:自 2012 年 12 月起,可以直接访问 xhr:
我用它来取消 ajax 文件上传。
链接 - https://github.com/malsup/form/issues/221
Since Dec 2012 it is possible to access xhr directly:
I use it to cancel ajax file upload.
link - https://github.com/malsup/form/issues/221