Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Envio de un reporte de error mediante una petcion HTTP POST de manera "cross-browser" y sin depender de librerías externas.
var sendErrorReport = function(error) {
var xhr = createXMLHTTPObject();
xhr.open('POST', endpointUrl, true);
xhr.send(error);
};
var createXMLHTTPObject = function() {
var xmlhttp, XMLHttpFactories = [
function() {
return new XMLHttpRequest();
},
function() {
return new ActiveXObject('Msxml2.XMLHTTP');
},
function() {
return new ActiveXObject('Msxml3.XMLHTTP');
},
function() {
return new ActiveXObject('Microsoft.XMLHTTP');
}
];
for (var i = 0; i < XMLHttpFactories.length; i++) {
try {
xmlhttp = XMLHttpFactories[i]();
// Use memoization to cache the factory
createXMLHTTPObject = XMLHttpFactories[i];
return xmlhttp;
} catch (e) {}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment