jQuery浏览器的停止按钮事件 [英] Jquery Browser's stop button event

查看:112
本文介绍了jQuery浏览器的停止按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以检测用户何时单击了任何浏览器上的停止按钮?当用户决定在上传文件时单击停止"按钮时,我想停止脚本的运行,以便触发脚本刷新页面.

Is there a way to detect when the user has clicked the stop button on any browser? I want to stop the script from running when the user decides to click the stop button when uploading a file, so I can trigger the script to refresh the page.

推荐答案

不幸的是,浏览器的停止"按钮不会影响AJAX请求.如果要取消AJAX请求,可以如下中止该请求:

Unfortunately the browser's stop button doesn't affect AJAX requests. If you want to cancel an AJAX request you can abort it like below:

var xhr = $.ajax(
    url: "http://someurl.org",
    success: function() { ... }
);

xhr.abort();

由于浏览器的停止"按钮无法中止请求,因此触发中止的按钮必须位于您的HTML中.但是,如果用户转到另一个页面,浏览器将停止监听,而这实际上就是您调用xhr.abort()时发生的情况.

The button to trigger the abort will need to be in your HTML since the browser's stop button cannot abort the request. If the user went to another page the browser would stop listening though and this is essentially what happens when you call xhr.abort().

这篇关于jQuery浏览器的停止按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆