fra98_

fetch

May 6th, 2021 (edited)
502
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let reqHeader = new Headers();
  2. reqHeader.append('Content-Type', 'text/json');
  3. reqHeader.append("accept", "application/json");
  4. reqHeader.append("Access-Control-Allow-Origin", "*");
  5.  
  6. let initObject = {
  7.     method: 'GET',
  8.     mode: 'no-cors',
  9.     headers: reqHeader
  10. };
  11.  
  12. let myRequest = new Request('https://www.dati.lombardia.it/resource/nmru-kdry.json', initObject);
  13.  
  14. fetch(myRequest)
  15. .then(response => {
  16.     console.log("Ricevo: ", response.status)
  17.     console.log("Da: ", response.url)
  18.     response.json()
  19. })
  20. .then(data => document.getElementById('content').innerHTML = data[0].denominazione)
  21. .catch(err => console.log("An Error: ", err))
RAW Paste Data