Skip to content
Browse files

Treat xhr.status==0 as error not success

For reasons mysterious to me, a network connection error on .ajax is treated as 'success' callback by jQuery, but with an xhr.status==0. Catch that in 'success' callback and treat it as error instead. This situation can happen for instance if the applicaiton the url is pointed at is down, and the server just doesn't accept a connection there.
  • Loading branch information...
1 parent e0c1904 commit 85db14d0cd296d5d0b1ce140a76862333216b3b9 @jrochkind committed Mar 3, 2011
Showing with 16 additions and 4 deletions.
  1. +16 −4 jquery.uiext.ajaxydialog.js
View
20 jquery.uiext.ajaxydialog.js
@@ -52,8 +52,14 @@
$.ajax({
url: url,
dataType: "html",
- success: function(resp, status) {
- self._loadToDialog(resp);
+ success: function(resp, status, xhr) {
+ if (xhr.status != 0) {
+ self._loadToDialog(resp);
+ } else {
+ //stupid jquery calling this 'success', it's
+ //network unavailable.
+ self._displayFailure(url, xhr, status);
+ }
},
error: function(xhr, msg) {
self._displayFailure(url, xhr, msg);
@@ -74,8 +80,14 @@
data: serialized,
type: form.attr("method").toUpperCase(),
dataType: "html",
- success: function(resp, status) {
- self._loadToDialog(resp);
+ success: function(resp, status, xhr) {
+ if (xhr.status != 0) {
+ self._loadToDialog(resp);
+ } else {
+ //stupid jquery calling this 'success', it's
+ //network unavailable.
+ self._displayFailure(url, xhr, status);
+ }
},
error: function(xhr, msg) {
self._displayFailure(actionUri, xhr, msg);

0 comments on commit 85db14d

Please sign in to comment.
Something went wrong with that request. Please try again.