lundi 30 novembre 2020

How save external csv using fetch Javascript to localForage (not localStorage)?

I try to save csv from outside, in response i see that i receive csv, but how to save it in localForage?

const url = "http://test.com/1.csv"; // site that doesn’t send Access-Control-*

fetch(url, {
    mode: "no-cors",
    headers: {
      'Content-Type': 'text/csv'
    }
  })

  .then(response => {
    return response.ok ? response.text() : Promise.reject(response.status);
  })




  .then(text => {
    return localforage.setItem('csv2', text)

  })
  .catch(error => console.log("Can’t access " + url + " response. Blocked by browser?" + error))



Aucun commentaire:

Enregistrer un commentaire