simple AJAX
var ajax = function(uri, cb) { | |
var xhr = new XMLHttpRequest(); | |
//xhr.withCredentials = true; // uncomment to send cookies and stuff | |
xhr.open('POST', uri, true); // GET OR POST... | |
var cbInner = function() { | |
if (xhr.readyState === 4 && xhr.status === 200) { | |
return cb(null, JSON.parse(xhr.response)); | |
} | |
cb('error requesting ' + uri); | |
}; | |
xhr.onload = cbInner; | |
xhr.onerror = cbInner; | |
xhr.send(null); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment