Last active
July 8, 2021 21:18
-
-
Save thiagosbrito/fe8fc4a5e484f703051dd6e7c7ca2710 to your computer and use it in GitHub Desktop.
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 httpRequest; | |
var makeHTTPRequest = function (url) { // se vc quiser tirar o parametro url, vc precisa passar a url na linha 22 | |
if (window.XMLHttpRequest) { | |
httpRequest = new XMLHttpRequest(); | |
} else if (window.ActiveXObject) { // quando nao for Chrome ou Safari | |
try { | |
httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); | |
} | |
catch (e) { | |
try { | |
httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
catch (e) {} | |
} | |
} | |
if (!httpRequest) { | |
alert('Ops, não foi possível criar uma instância de HTTP no momento'); | |
return false; | |
} | |
httpRequest.onreadystatechange = logResponse(httpRequest.responseText); | |
httpRequest.open('GET', url); // se for o caso de nao usar o parametro, substituir a variavel url pelo endereco | |
httpRequest.send(); | |
} | |
var logResponse = function (response) { | |
console.info(response); | |
} | |
// Não se esqueça que esse código precisa ser executado por um dominio mesmo que seja localhost |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment