/ Published in: JavaScript

Get JSON data from server via Fetch API
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
fetch('products.json') // some API path // as response comes in form of string we use response.json to parse it in JSON .then(function(response) { return response.json(); }) // parse JSON in form of parameter innext line .then(function(json) { for(var i = 0; i < json.products.length; i++) { console.log(json.products[i]) } });
Comments
