Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript fetch json

fetch('./yourjson.json')
  .then((response) => response.json())
  .then((data) => {
  	console.log(data);
  })
Comment

js fetch json

var myRequest = new Request('products.json');//GET
var myRequest = new Request('products.json', {method: "post"});//POST

fetch(myRequest)
  .then(response => response.json())
  .then(data => {
    console.log(data);
  })
  .catch(console.error);
Comment

javascript fetch APIjson

//Set URL from External Variable
const url = '{{url}}';
//Set Admin P from Input variable
const adminP = '{{adminP}}';
//Set Admin Password from input variable
const adminPW = '{{adminPW}}';


fetch(url)
    .then(res => res.json())
    .then(data => {
        // code to handle the response
    }).catch(err => {
        console.error('Error: ', err);
    });
    
    
// create an element
const createNode = (elem) => {
    return document.createElement(elem);
};
// append an element to parent
const appendNode = (parent, elem) => {
    parent.appendChild(elem);
}
// ...
.then(data => {
    // iterate over response
    data.map((responseD) => {
        // create the elements
        let li = createNode('li'),
            img = createNode('img'),
            span = createNode('span');
        img.src = user.avatar_url;
        span.innerText = user.login;
        // append all elements
        appendNode(li, img);
        appendNode(li, span);
        appendNode(ul, li);
    });
})
//...
Comment

PREVIOUS NEXT
Code Example
Javascript :: js concat 
Javascript :: convert celsius to fahrenheit javascript 
Javascript :: multi-dimensional array js 
Javascript :: netlify page not found on refresh vuejs vue-router 
Javascript :: google autocomplete not returning lat long 
Javascript :: JSX Conditionals: && 
Javascript :: chartjs templates 
Javascript :: jquery vs react 
Javascript :: closest js 
Javascript :: how to print two arrays together 
Javascript :: .includes is not a function 
Javascript :: import javascript 
Javascript :: add 
Javascript :: discord js if no arguments 
Javascript :: jQuery intellisence in VSCode 
Javascript :: javascript ajax get 
Javascript :: nodejs http 
Javascript :: reactjs change fill color .svg 
Javascript :: button disable in js 
Javascript :: nested ternarys javascript 
Javascript :: promise all 
Javascript :: detect dark mode 
Javascript :: jquery modal show 
Javascript :: react typescript set type 
Javascript :: image upload using jquery ajax 
Javascript :: Add remove link dropzone 
Javascript :: using datatable 
Javascript :: javascript htmlcollection 
Javascript :: Children in JSX 
Javascript :: array limit js 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =