stackoverflow response controlar erro jquery ajax

by andres descalzo

JavaScript

$(function() {
    
    var xhr = null;
    
    if (window.XMLHttpRequest) {
        xhr = window.XMLHttpRequest;
    }
    else if(window.ActiveXObject('Microsoft.XMLHTTP')){
        // I do not know if this works
        xhr = window.ActiveXObject('Microsoft.XMLHTTP');
    }
    
    var send = xhr.prototype.send;
    xhr.prototype.send = function(data) {
        try{
            //TODO: comment the next line
            console.log('pre send', data);
            send.call(this, data);
            //TODO: comment the next line
            console.log('pos send');
        }
        catch(e) {
            //TODO: comment the next line
            console.log('err send', e);
        }
    };
    
    $.ajax({
        dataType: 'xml',
        url: '/echo/xml/?sid=' + (new Date()).getTime(),
        success: function (data) {
            console.log('success', data);
        },
        error: function (error) {
            console.log('error', error);
        }
    });
});