Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <!-- this changed -->
- <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script>
- <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
- </head>
- <body>
- <p id="demo"></p>
- <script>
- function myDisplayer(some) {
- document.getElementById("demo").innerHTML = some;
- }
- function getFile(myCallback) {
- let req = new XMLHttpRequest();
- req.open('GET', "test.json");
- req.onload = function() {
- if (req.status === 200) {
- myCallback(this.responseText);
- } else {
- myCallback("Error: " + req.status);
- }
- };
- req.send();
- }
- getFile(myDisplayer);
- </script>
- <script type="text/javascript">
- document.getElementById('demo')
- .addEventListener('change', function () {
- let fileReader = new FileReader();
- fileReader.onload = function () {
- let parsedJSON = Object.values(JSON.parse(fileReader.result));
- console.log(parsedJSON);
- // your code to consume the json
- }
- fileReader.readAsText(this.files[0]);
- });
- </script>
- <script>
- // setInterval(function() {
- //
- // $(demo).load('test.json');
- //}, 1000);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment