开发者

How to cancel a file upload?

I w开发者_JS百科ant to know how I can cancel a file upload with a form multipart/form-data. Is that possible?


Make the form post to a hidden iframe. Change the iframe src when you want to cancel. The browser will reload the iframe and cancel the previous POST request on it.


The upload is a user's browser POSTing the data up to the server. You'll need to cancel it on the user-side. Unfortunately, JS is single-threaded (usually) so it's hard to interrupt it.

You can use JavaScript to change the upload URL (to nothing, LocalHost, etc) if you first have the upload pointed to an iFrame. You can change the iFrame SRC mid-stream. You can also refresh the page or take the user to a new page from the iFrame back to the parent.

These iFrame tricks are ways to 'interrupt the upload on the main page'.

You can also provide cancel buttons that should capture user events (clicks) that change the URL of the page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜