Handle ajax errors using struts2-jquery-plugin

We have a web application using struts2 with struts2-jquery-plugin, we need to capture 403 HTTP errors to redirect to the login page when an ajax request is requested. We put this code:

$(function () {
    //setup ajax error handling
    $.ajaxSetup({
        error: function (x, status, error) {
            if (x.status == 403) {
                redirectToLogin();
            } else {
                manageAjaxError(status, error);
            }
        }
    });
});

This is normal for all ajax requests, but does not work for jquery requests from struts2-jquery-plugin (for example: a call from the sj: submit button), the code above does not execute.

Found one onErrorTopics solution found for each tag, but it doesn’t work in the tabs (this may be an error).

Can I set a global processing error for queries from struts-jquery-plugin?

+4
source share
1

, error.status - , ,

$(function () {
    //setup ajax error handling
    $.ajaxSetup({
        error: function (x, status, error) {
            if (error.status == 403) {
                redirectToLogin();
        } else {
            manageAjaxError(status, error);
        },

        complete: function (response, textStatus, jqXHR) {
            console.log(jqXHR);
        }
    })
});
0

Source: https://habr.com/ru/post/1538031/


All Articles