Last active
August 29, 2015 13:56
-
-
Save josketres/9161205 to your computer and use it in GitHub Desktop.
Envio de un reporte de error mediante una petcion HTTP POST de manera "cross-browser" y sin depender de librerías externas.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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