Created
July 1, 2015 14:13
-
-
Save MickaelCruzDB/652869337b7bc3487594 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
var getJSON = function(url, successHandler, errorHandler) { | |
var xhr = typeof XMLHttpRequest != 'undefined' | |
? new XMLHttpRequest() | |
: new ActiveXObject('Microsoft.XMLHTTP'); | |
xhr.open('get', url, true); | |
xhr.onreadystatechange = function() { | |
var status; | |
var data; | |
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-readystate | |
if (xhr.readyState == 4) { // `DONE` | |
status = xhr.status; | |
if (status == 200) { | |
data = JSON.parse(xhr.responseText); | |
successHandler && successHandler(data); | |
} else { | |
errorHandler && errorHandler(status); | |
} | |
} | |
}; | |
xhr.send(); | |
}; | |
getJSON('http://icontrol.herokuapp.com/api/product/1/?format=json', function(data) { | |
document.write(data.activated) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment