Skip to content

Instantly share code, notes, and snippets.

@FelisPhasma
Last active July 11, 2016 22:39
Show Gist options
  • Save FelisPhasma/b1ba6e4eefa68611ac79 to your computer and use it in GitHub Desktop.
Save FelisPhasma/b1ba6e4eefa68611ac79 to your computer and use it in GitHub Desktop.
Making ajax super easy to use!
// Copyright (c) 2015 FelisPhasma
/*
Ussage:
ajax("GET", "url", true, function(status, responseText){
if (readyState==4 && status==200){
//...
}
})
*/
function ajax(method, url, async_, callback){
var xmlhttp;
if (window.XMLHttpRequest)
xmlhttp = new XMLHttpRequest();
else
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState==4){
callback(xmlhttp.status, xmlhttp.responseText);
}
};
xmlhttp.open(method, url, async_);
xmlhttp.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment