M
M
Mmx Symfony2020-12-01 14:45:41
JavaScript
Mmx Symfony, 2020-12-01 14:45:41

How to store the contents of an external Csv file into a variable in Javascript?

I can't figure out what I'm doing right? I need to transfer the body of the Csv file to a variable

const url = "http://www.aaa.com/uploads/1.csv"; // 
fetch(url, {
    mode: "no-cors",
    headers: {
        'Content-Type': 'text/csv'
    }
})
    .then(response => {
        return response.ok ? response.text() : Promise.reject(response.status);
    })
    .then(text => {
        return console.log(text.toString())
    })
    .catch(error => console.log("Can’t access " + url + " response. Blocked by browser?" + error))


Mistake
Can’t access http://www.aaa.com/uploads/1.csv response. Blocked by browser? 0

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Yakimchuk, 2020-12-01
@yakimchuk-ry

Can't access www.aaa.com/uploads/1.csv response. Blocked by browser? 0

Code 0 indicates network problems. Check the availability of the resource to rule out network problems.
If the resource is available, then the problem is on the browser side, dig towards security and certificates (usually towards CORS or HTTPS certificates).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question