Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

fetch json file

fetch('./server.json')
	.then(response => response.json())
	.then(data => console.log(data))
	.catch(err => console.error(err));
Comment

fetchData from json file

const fetchData = async () => {
  try {
    const res = await fetch("js/data.json");
    data = await res.json();
    displayData(data);
  } catch (e) {
    console.log("something went wrong!", e);
  }
};

fetchData();
Comment

read json file with fetch

const todoUrl ='https://jsonplaceholder.typicode.com/todos';
  
function getAllTodos(){
        return new Promise((resolve => {
            fetch(new Request(todoUrl)).
            then( res => {
                return res.json();
            })
            .then(data => {resolve(data);
            });
        }))
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: express get ip address of request 
Javascript :: Vanilla JS (on)load with page 
Javascript :: javascript number methods 
Javascript :: p5.js create button 
Javascript :: replace object in array javascript 
Javascript :: for array javascript 
Javascript :: gulp del 
Javascript :: find element in array javascript 
Javascript :: create a category discord.js 
Javascript :: Found multiple occurrences of org.json.JSONObject on the class path: 
Javascript :: js create timestamp with 10 digits 
Javascript :: js export as name 
Javascript :: javascript confirm delete 
Javascript :: javascript is valid json string 
Javascript :: set element position js 
Javascript :: next router push state 
Javascript :: get a href value javascript 
Javascript :: javascript number pyramid 
Javascript :: split a message 
Javascript :: how to cheack if a number is an integer or float in javascript 
Javascript :: jquery disable keypress 
Javascript :: remove element from array in an immutable way 
Javascript :: javascript maximum date 
Javascript :: js console.log color 
Javascript :: how to find length of array js 
Javascript :: loop key in object 
Javascript :: send data in res.render in express js 
Javascript :: get first word of string js 
Javascript :: window closing event js 
Javascript :: clear textbox js 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =