Created
March 25, 2013 07:06
-
-
Save fczbkk/5235391 to your computer and use it in GitHub Desktop.
Minimalist AJAX function for the most basic calls. Only supports GET method. Loads given url and sends result to the callback function. Callback attribute is optional, sometimes you just want to ping the server and you don't care about the response.
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 (url, callback) { | |
callback = callback || function () {}; | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState == 4) { | |
callback(xhr.responseText); | |
} | |
}; | |
xhr.open("GET", url, true); | |
xhr.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Many thanks! Simple and short.