Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let jsonParser = (function() {
- let that = {
- jsonResponse: null,
- parsedJSON: null,
- load: function(filepath, callback) {
- let jsonObject = new XMLHttpRequest();
- jsonObject.overrideMimeType("application/json");
- jsonObject.open('GET', filepath, true);
- jsonObject.onreadystatechange = function() {
- if (jsonObject.readyState == 4 && jsonObject.status == "200") {
- callback(jsonObject.responseText);
- }
- }
- jsonObject.send(null);
- },
- parse: function() {
- let parsedJSON = JSON.parse(that.jsonResponse);
- return that.parsedJSON;
- },
- };
- return {
- load: that.load,
- parse: that.parse,
- };
- })();
- let response;
- jsonParser.load('data.json', () => {response = jsonParser.parse});
- console.log(response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement