Can I get data from an ajax request using the global .ajaxSuccess handler?

I created a global handler for ajaxSuccess, but I need to be able to examine the data for each request. Is it possible to access the returned data at this point?

jQuery(document).ajaxSuccess(function(event, request, options) {
    // i can has the datas? >^..^<
});
+3
source share
2 answers

This works in FF, Chrome, IE 8:

jQuery(document).ajaxSuccess(function(event, request, options) {
    if (options.dataType == 'json') {
        var data = JSON.parse(request.responseText);
        // i has the datas!
    }
});
+2
source
jQuery(document).ajaxSuccess(function(event, request, options, data) {
        console.log(data);
});
0
source

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


All Articles