Created
August 21, 2008 04:17
-
-
Save ELLIOTTCABLE/6508 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Uses XMLHttpRequest to get a json object from a URI | |
function JSONHttpRequest(URI, onResponse, method_opt, charset_opt){ | |
var method = method_opt || 'GET'; | |
var charset = charset_opt || 'utf-8'; | |
var request = new XMLHttpRequest(); | |
request.open(method, URI, true); | |
request.setRequestHeader("Content-Type", "application/json;charset=" + charset); | |
request.onreadystatechange = function() { | |
if (request.readyState == 4 && request.status == 200) { | |
if (request.responseText) { | |
console.log(JSON.parse(request.responseText)['body']); | |
onResponse.call(JSON.parse(request.responseText)['body']); | |
} | |
} | |
} | |
request.send(null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment