Skip to content

Instantly share code, notes, and snippets.

@jsoverson
Created October 26, 2012 16:39
Show Gist options
  • Save jsoverson/3959808 to your computer and use it in GitHub Desktop.
Save jsoverson/3959808 to your computer and use it in GitHub Desktop.
Simple ajax lib
function ajax(url, cb, postData) {
var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
request.onreadystatechange = function () {
console.log('what');
if (request.readyState==4)
cb(request.responseText);
};
if (postData) {
request.open("POST", url, true);
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
request.setRequestHeader('Connection', 'close');
} else {
request.open("GET", url, true);
}
request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
request.send(postData || '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment