user0918232
user0918232

Reputation: 109

Axios cors header not appearing on request

I have an axios request to the backend. And our backend said that he already configure the cors for the front end. But when I send my axios request. It only gets me this headers even if I put an header in my post request.

enter image description here

Here is my axios

           for (var i = 0; i < this.rows.length; i++) {
                  console.log(this.rows[i].from)
                  console.log(this.rows[i].to)
                  axios.post(' https://pa-staging.propnex.net/index.php/public/addDiyOpenhouse?listing-id=506&start-time='+this.rows[i].from +'&end-time='+this.rows[i].to+'&date=2020-06-20',{
                      headers: {
                      'Accept': 'application/json',
                      'Content-Type': 'application/json',
                    }
                  }).then((res)=>{
                    console.log(res);
                  })
              }

Upvotes: 1

Views: 162

Answers (1)

User81646
User81646

Reputation: 753

The axios.post API dictates that the second parameter is for data (like form data or json, etc) and headers can be defined in the third parameter. So change you line to this syntax:

axios.post(url, requestData (or empty object for no data), {headers: { headerName: headerValue }})

Upvotes: 1

Related Questions