Created
October 26, 2012 16:39
-
-
Save jsoverson/3959808 to your computer and use it in GitHub Desktop.
Simple ajax lib
This file contains 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, 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