有一种方法来处理来自JQuery中的ajax请求的错误,使得当用户导航离开页面时,所产生的错误被忽略?
- $(document).ready(function() {
- $.ajax( {
- url:'/server/url/',type: 'POST',data: {some..data},success:function(response) { do stuff with response },error: function(xhr,textStatus,errorThrown) {
- // Don't raise this alert if user has navigated away from the page
- alert('error');
- }
- });
我很好奇,如果有人知道一个干净的方式来处理这个?我知道你可以在$(窗口).bind(“beforeunload”,function(){})方法中创建一些逻辑,但我更喜欢如果有一种方法来处理这种情况,而不这样做,因为Chrome似乎不再支持它。例如,在这种情况下返回的具体错误?
谢谢。