Properly implement ajax fail callback
This commit is contained in:
parent
0a47adb419
commit
a292f5d73e
1 changed files with 32 additions and 37 deletions
|
@ -180,7 +180,7 @@ function display_message(containerId, alertType, message, callback) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function api_call(method, url, data, callback) {
|
function api_call(method, url, data, callback_success, callback_fail) {
|
||||||
if (method.toLowerCase() == "post") {
|
if (method.toLowerCase() == "post") {
|
||||||
data["csrf_token"] = $.cookie("csrf_token");
|
data["csrf_token"] = $.cookie("csrf_token");
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ function api_call(method, url, data, callback) {
|
||||||
"datatype": "json",
|
"datatype": "json",
|
||||||
"data": data,
|
"data": data,
|
||||||
"url": url
|
"url": url
|
||||||
}).done(callback);
|
}).done(callback_success).fail(callback_fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
$.fn.serializeObject = function() {
|
$.fn.serializeObject = function() {
|
||||||
|
@ -224,9 +224,9 @@ var register_form = function() {
|
||||||
button.removeAttr("disabled");
|
button.removeAttr("disabled");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).fail(function(jqXHR, status, error) {
|
}, function(jqXHR, status, error) {
|
||||||
var result = JSON.parse(jqXHR["responseText"]);
|
var result = jqXHR["responseText"];
|
||||||
display_message("register_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
|
display_message("register_msg", "danger", "Failed to connect to the API.", function() {
|
||||||
button.removeAttr("disabled");
|
button.removeAttr("disabled");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -245,9 +245,9 @@ var request_reset_form = function() {
|
||||||
button.removeAttr("disabled");
|
button.removeAttr("disabled");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).fail(function(jqXHR, status, error) {
|
}, function(jqXHR, status, error) {
|
||||||
var result = JSON.parse(jqXHR["responseText"]);
|
var result = jqXHR["responseText"];
|
||||||
display_message("reset_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
|
display_message("reset_msg", "danger", "Failed to connect to the API.", function() {
|
||||||
button.removeAttr("disabled");
|
button.removeAttr("disabled");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -270,9 +270,9 @@ var reset_form = function() {
|
||||||
button.removeAttr("disabled");
|
button.removeAttr("disabled");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).fail(function(jqXHR, status, error) {
|
}, function(jqXHR, status, error) {
|
||||||
var result = JSON.parse(jqXHR["responseText"]);
|
var result = jqXHR["responseText"];
|
||||||
display_message("reset_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
|
display_message("reset_msg", "danger", "Failed to connect to the API.", function() {
|
||||||
button.removeAttr("disabled");
|
button.removeAttr("disabled");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -293,9 +293,9 @@ var login_form = function() {
|
||||||
button.removeAttr("disabled");
|
button.removeAttr("disabled");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).fail(function(jqXHR, status, error) {
|
}, function(jqXHR, status, error) {
|
||||||
var result = JSON.parse(jqXHR["responseText"]);
|
var result = jqXHR["responseText"];
|
||||||
display_message("login_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
|
display_message("login_msg", "danger", "Failed to connect to the API.", function() {
|
||||||
button.removeAttr("disabled");
|
button.removeAttr("disabled");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -316,9 +316,9 @@ var create_team = function() {
|
||||||
button.removeAttr("disabled");
|
button.removeAttr("disabled");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).fail(function(jqXHR, status, error) {
|
}, function(jqXHR, status, error) {
|
||||||
var result = JSON.parse(jqXHR["responseText"]);
|
var result = jqXHR["responseText"];
|
||||||
display_message("create_team_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
|
display_message("create_team_msg", "danger", "Failed to connect to the API.", function() {
|
||||||
button.removeAttr("disabled");
|
button.removeAttr("disabled");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -333,13 +333,8 @@ var add_member = function() {
|
||||||
if (result["success"] == 1) {
|
if (result["success"] == 1) {
|
||||||
location.reload(true);
|
location.reload(true);
|
||||||
} else {
|
} else {
|
||||||
button.removeAtr("disabled");
|
|
||||||
}
|
|
||||||
}).fail(function(jqXHR, status, error) {
|
|
||||||
var result = JSON.parse(jqXHR["responseText"]);
|
|
||||||
display_message("create_team_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
|
|
||||||
button.removeAttr("disabled");
|
button.removeAttr("disabled");
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue