Skip to content

Instantly share code, notes, and snippets.

@caubry
Last active January 3, 2016 08:39
Show Gist options
  • Save caubry/8437294 to your computer and use it in GitHub Desktop.
Save caubry/8437294 to your computer and use it in GitHub Desktop.
function xhrGet(reqUri, callback, type) {
var caller = xhrGet.caller;
var xhr = new XMLHttpRequest();
xhr.open("GET", reqUri, true);
if (type) xhr.responseType = type;
xhr.onload=function () {
if (callback) {
try {
callback(xhr);
}
catch(e) {
throw 'xhrGet failed:\n' + reqUri + '\nException: ' + e + '\nresponseText: ' + xhr.responseText + '\ncaller: ' + caller;
}
}
};
xhr.send();
};
parseJSON = function (xhr) {
var parsedJSON = JSON.parse(xhr.responseText);
var x = parsedJSON['frames']['chaingun_impact.png']['spriteSourceSize']['x'];
console.log(x);
return x;
};
xhrGet('weaponJSON', parseJSON, null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment