Last active
December 12, 2015 05:45
-
-
Save hyeonseok/604812e389aa9e74d346 to your computer and use it in GitHub Desktop.
Minimal Ajax function
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
// Minimal Ajax function https://gist.github.com/hyeonseok/604812e389aa9e74d346 | |
function ajax(u,c,d){var x=new(this.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP");x.onreadystatechange=function(){this.readyState^4||c(this)};if(d){x.open('POST',u);x.setRequestHeader('Content-type','application/x-www-form-urlencoded')}else{x.open('GET',u)}x.send(d)} | |
/* | |
GET request | |
ajax('whatever.php?foo=bar', function (xhr) { | |
console.log(xhr.responseText); | |
}); | |
POST request | |
ajax('whatever.php', function (xhr) { | |
console.log(xhr.responseText); | |
}, 'foo=bar'); | |
Inspired by | |
- https://code.google.com/p/microajax/ | |
- https://gist.github.com/azproduction/1625623 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment