diff options
Diffstat (limited to 'fg21sim/webui/static')
-rw-r--r-- | fg21sim/webui/static/js/main.js | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/fg21sim/webui/static/js/main.js b/fg21sim/webui/static/js/main.js index 27638a7..64b65c1 100644 --- a/fg21sim/webui/static/js/main.js +++ b/fg21sim/webui/static/js/main.js @@ -9,12 +9,19 @@ /** - * jQuery settings + * jQuery AJAX global callbacks using the global AJAX event handler methods + * + * NOTE: + * It is NOT recommended to use `jQuery.ajaxSetup` which will affect ALL calls + * to `jQuery.ajax` or AJAX-based derivatives. */ -jQuery.ajaxSetup({ - error: function (error) { - console.error("AJAX request failed: code:", error.status, - ", reason:", error.statusText); } +$(document).ajaxError(function (event, jqxhr, settings, exception) { + console.error("AJAX request failed: code:", jqxhr.status, + ", reason:", jqxhr.statusText); + if (jqxhr.status === 403) { + // Forbidden error: redirect to login page + window.location.href = "/login"; + } }); @@ -37,6 +44,7 @@ var getCookie = function (name) { return m ? m[1] : undefined; }; + /** * jQuery extension for easier AJAX JSON post * |