Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

load json object from file frontend javascript

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);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: logvalue returned from array 
Javascript :: vue2-editor save image 
Javascript :: @Scheduled cron expresssion 
Javascript :: browser console unhide element 
Javascript :: set-date-picker-range-with-in-a-financial-year-based-on-the-document 
Javascript :: babel 7 ReferenceError: regeneratorRuntime 
Javascript :: jQuery form upload 
Javascript :: React sub count 
Javascript :: getters and setters in java script 
Javascript :: iterate set javascript 
Javascript :: illegal start of expression spring boot 
Javascript :: experess Routing 
Javascript :: how to add datepicker in appended input 
Javascript :: Text with prop value is rendered The component renders variable text based on a string prop. We test that the component renders the value of the passed prop. 
Javascript :: javascript intersect two object arrays 
Javascript :: dynamic copyright year JavaScript centre aligned 
Javascript :: await multiple promises 
Javascript :: check if element is displayed 
Javascript :: convert json results 
Javascript :: javaScript Bezier Curve After Effects expression 
Javascript :: How can I use a regex variable in a query for MongoDB 
Javascript :: && in javascript new 
Javascript :: Alternative Syntax For Backbone Simple Template 
Javascript :: How to Use the Return Keyword in a Function 
Javascript :: jquery init dropdown 
Javascript :: react button on child Content Data initialize 
Javascript :: Use regular function with DOM event listeners, when using "this" keyword 
Javascript :: Changing Prototype 
Javascript :: onSeek video getting paused 
Javascript :: pass prop through route 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =