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 :: JavaScript performing an integer division 
Javascript :: javascript print numbers in the given range 
Javascript :: jquery clear click event 
Javascript :: .on change get value 
Javascript :: get value of input element on button click react 
Javascript :: npm react router dom 
Javascript :: exceljs column pick from drop down list 
Javascript :: initialize json array 
Javascript :: string reduction javascript 
Javascript :: javascript removing items looping through array 
Javascript :: momentjs date and time string add minutes 
Javascript :: jquery datatable export button not showing 
Javascript :: get current platform react native 
Javascript :: fizzbuzz js 
Javascript :: #react native shadow 
Javascript :: react native metro api level 30 
Javascript :: javascript eliminar items repetidos 
Javascript :: react native monorepo module resolver outside app 
Javascript :: jquery set multiple css properties 
Javascript :: get channel id discord js v12 
Javascript :: eslint linebreak style 
Javascript :: how to close another browser tab with javascript 
Javascript :: javascript find link by href 
Javascript :: adonisjs livereload 
Javascript :: how to use pass value to the function that was called onchange in react 
Javascript :: regex to remove spaces 
Javascript :: c# json foreach key value 
Javascript :: get the first word from a string jquery 
Javascript :: iscolor 
Javascript :: run a nodejs file infinite loop 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =