处理当用户点击刷新Ajax错误 [英] handle ajax error when a user clicks refresh
问题描述
我道歉,如果这是我应该能够抬起头来。所有我想是这样超负荷的条款。
i apologise if this is something i should be able to look up. all of the terms i wanted were way overloaded..
下面是我的问题:当我打开一个网页,它触发了整个系列的Ajax调用。如果我再preSS Shift +刷新,所有这些Ajax调用正在考虑的错误,并显示整个页面本身重新加载之前他们错误信息的对话框。
here is my problem: when i open a page, it fires off a whole series of ajax calls. if i then press Shift+Refresh, all of those ajax calls are being considered errors, and showing their error message dialogs before the entire page itself reloads.
因此错误是由客户端引发的 - 有反正我可以找出如果是这样我就可以忽略它了呢?例如,在xmlhtt prequest,或在AJAX功能(我使用jQuery的BTW)
so the error is being triggered by the client - is there anyway i can find out if this is the case so i can ignore it? eg in the xmlhttprequest, or in the ajax function (i am using jquery btw)
推荐答案
[这是从previous的答案,其中有我有,因为解决悬而未决的问题编辑]
[this is an edit from the previous answer, which had outstanding questions that I have since resolved]
jQuery的引发错误事件在用户离开页面或者通过令人耳目一新,点击一个链接,或改变浏览器的URL。您可以通过检测这些类型的错误通过实现Ajax调用错误处理程序,并检查xmlHtt prequest对象:
jQuery throws the error event when the user navigates away from the page either by refreshing, clicking a link, or changing the URL in the browser. You can detect these types of errors by by implementing an error handler for the ajax call, and inspecting the xmlHttpRequest object:
$.ajax({
/* ajax options omitted */
error: function (xmlHttpRequest, textStatus, errorThrown) {
if(xmlHttpRequest.readyState == 0 || xmlHttpRequest.status == 0)
return; // it's not really an error
else
// Do normal error handling
});
这篇关于处理当用户点击刷新Ajax错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!