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

get jsonp with fetch

fetchJsonp('/users.jsonp')
  .then(function(response) {
    return response.json()
  }).then(function(json) {
    console.log('parsed json', json)
  }).catch(function(ex) {
    console.log('parsing failed', ex)
  })
Comment

PREVIOUS NEXT
Code Example
Javascript :: How to Display a List in React 
Javascript :: javascript access ajax response headers 
Javascript :: how to apply border to table in angular 
Javascript :: how to get class name of element in javascript 
Javascript :: Flatten a multidimension array 
Javascript :: difference between undefined and null javascript 
Javascript :: java hashmap get array of keys 
Javascript :: define an async function 
Javascript :: without refresh update url in js 
Javascript :: Javascript make alert box 
Javascript :: js random generator 
Javascript :: react-bootstrap problem-install new version 
Javascript :: js map key value 
Javascript :: extract string from string javascript based on word 
Javascript :: add even numbers recursion js 
Javascript :: feet to mile js 
Javascript :: compare date and time in js 
Javascript :: how to add all values of array together js 
Javascript :: electron load index.html 
Javascript :: validar array vacio javascript 
Javascript :: vue js app component 
Javascript :: how to get input with name in jest test 
Javascript :: js scroll to bottom exact 
Javascript :: firebase messaging import script 
Javascript :: react native flatlist container style 
Javascript :: toFixed() javascript precision 
Javascript :: what is redis 
Javascript :: define maxmum size of schema field in nodejs 
Javascript :: refresh a single component 
Javascript :: jest testing with ResizeObserver 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =