Home > Blockchain >  Axios: sending 204 request with post
Axios: sending 204 request with post

Time:10-04

When ever I am sending a POST request using Vue.js(3.x) an addition request to same url is getting triggered with the status code = 204 and type = preflight;

Register.vue

async submit() {
    this.button = true;

    try {
        const response = await axios.post(`register`, this.form);

        if(response.data.success == false)
        {
            console.log(response.data.message);
        }
        else
        {
            this.$router.push('/');
        }
    }
    catch (error)
    {
        let { errors } = error.response.data;

        this.button = false;
        this.errors = {};

        Object.keys(errors).forEach(element => {
            this.errors[element] = errors[element][0];
        });
    }
},

enter image description here

How to fix this issue.?

CodePudding user response:

This is not an issue and is controlled by the browser by design.

It is not something Axios or any other HTTP client decides to send.

A preflight request is a CORS OPTIONS request & are automatically sent by browsers specifically to check if the server would support the call you are trying to make in terms of method, headers and origin.

You can safely ignore the requests if they do not fail as that means that the server will not be rejecting your request on the basis of the aforementioned factors.

Your issue relates to the endpoint not existing as you are getting a 404 Not Found error - check to see if the endpoint exists or if you are calling it correctly.

  • Related