E
E
EastJesus2018-12-03 23:20:31
JavaScript
EastJesus, 2018-12-03 23:20:31

Why can't Axios see the file?

Hello, on Vue.JS using Axios I get data from a JSON file, everything works fine:

created() {
        axios
        .get('http://localhost:8080/json/cars.json')
        .then(response => (this.info = response.data));
    }

But I'm trying to enter data into the same file, the console returns 404 (file not found), what's wrong?
axios.post('http://localhost:8080/json/cars.json', {
                id: '3',
                name: 'Flintstone'
            })

The file is stored in public/json/cars.json, I tried to throw it at the root, it does not help

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Proskurin, 2018-12-03
@EastJesus

You cannot directly enter data to the server through the client (JS). There must be a script on the server that takes your data, validates it, and saves it to a file.

K
Kirill Romanov, 2018-12-03
@Djaler

It doesn't work like that. On the server side, there should be a POST request handler that will update the contents of the file

I
imhuman, 2018-12-03
@imhuman

Are you sure this is how you write to the file?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question