Skip to content

Instantly share code, notes, and snippets.

@S204STi
S204STi / gist:221c7b72641b1ef4ee5cd796fd4aed74
Created May 22, 2016 21:04 — forked from loganking/gist:4be8161ea628fba57437f490c22e2b39
AJAX wrapper for XMLHttpRequest supporting GET and POST
/*
data (optional) - a JSON string to send with the request
*/
function ajax(method, url, handler, data) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (this.readyState === 4) {
if (this.status === 200) {
handler(null, JSON.parse(this.responseText));