Posted By

sudhiakki on 07/24/17


Tagged

fetch


Versions (?)

JS Fetch: Get JSON data from server


 / Published in: JavaScript
 

Get JSON data from server via Fetch API

  1. fetch('products.json') // some API path
  2. // as response comes in form of string we use response.json to parse it in JSON
  3. .then(function(response) { return response.json(); })
  4. // parse JSON in form of parameter innext line
  5. .then(function(json) {
  6. for(var i = 0; i < json.products.length; i++) {
  7. console.log(json.products[i])
  8. }
  9. });

Report this snippet  

You need to login to post a comment.