JSFiddle - React, Tailwind, and code Playground

JavaScript

function erroAjax(e) {
   alert('Houve um erro no ajax!');
}

function novoXHR() {
    var xhr = new XMLHttpRequest();
    xhr.addEventListener("error", erroAjax, false);
    return xhr;
}

var xhr1 = novoXHR(); // deve funcionar
var xhr2 = novoXHR(); // vai dar erro

xhr1.open('POST', '/echo/html/', true);
xhr1.send('foo=bar');


xhr2.open('POST', 'http://stackoverflow.com', true);
xhr2.send('&');