Skip to content

Instantly share code, notes, and snippets.

@MRezaSafari
Created April 25, 2016 07:21
Show Gist options
  • Save MRezaSafari/a66f3891d334b6183f488098cb2fa536 to your computer and use it in GitHub Desktop.
Save MRezaSafari/a66f3891d334b6183f488098cb2fa536 to your computer and use it in GitHub Desktop.
function readTextFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/json");
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4 && rawFile.status == "200") {
callback(rawFile.responseText);
}
}
rawFile.send(null);
}
//usage:
readTextFile("/Users/Documents/workspace/test.json", function(text){
var data = JSON.parse(text);
console.log(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment