Created
April 8, 2017 07:22
-
-
Save juliozuppa/0e7bfb61a64aff74fb1b705b69ef370a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function ajax(method, url, callback) { | |
var xmlhttp; | |
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari | |
try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } | |
} else { // code for IE6, IE5 | |
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { | |
try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { xmlhttp = false; } | |
} | |
} | |
if (!xmlhttp) { alert("Erro ao criar o objeto XMLHttpRequest"); return; } | |
xmlhttp.onreadystatechange = function () { | |
if (xmlhttp.readyState === XMLHttpRequest.DONE) { | |
if (xmlhttp.status === 200) { | |
callback(xmlhttp.responseText); | |
} else { | |
alert("Error" + xmlhttp.statusText); | |
} | |
} | |
} | |
xmlhttp.open(method, url, true); | |
xmlhttp.onerror = function () { | |
alert("Ocorreu algum erro durante a transação ajax!"); | |
}; | |
xmlhttp.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment