Skip to content

Instantly share code, notes, and snippets.

@fczbkk
Created March 25, 2013 07:06
Show Gist options
  • Select an option

  • Save fczbkk/5235391 to your computer and use it in GitHub Desktop.

Select an option

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.
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();
}
@denysdovhan
Copy link
Copy Markdown

Many thanks! Simple and short.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment