S
S
sa1ch2020-05-08 14:24:34
Vue.js
sa1ch, 2020-05-08 14:24:34

How to send json via axios?

Hello! Faced the following problem:
I'm trying to send json via axios to my backend:

axios .post(this.url, data, {
                    headers: {
                        'Content-Type': 'application/json',
                        Accept: 'application/json'
                    }
                })
                .then(response => (
                    this.resCalc = response
                ))
                .catch(function (error) {
                    console.log(error);
                });


An error appears in the console: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Although the headers on cors are written in the backend.
If you remove the headers from the axios request, then the data is transferred and there are no errors on the frontend side.
But then Content-Type comes: application/x-www-form-urlencoded this does not suit me, I just need json.

I have already looked through the entire github axios and tried everything I found. There are no results. How to get out of this situation?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question