abu abu
abu abu

Reputation: 7028

Error in console of AXIOS

I am using axios in reactjs application. My code is like below

axios.post('/api/addresses/upload/',formData,config)
  .then(function (response) {

  })
  .catch(error => {
  });

I did not use any console.log() statement any where but I am getting below error in console.

enter image description here

How this error printed in console ?

Upvotes: 6

Views: 8206

Answers (1)

Jeeva
Jeeva

Reputation: 1590

Try by setting the header for the axios request,

The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions.

May be you will be missing some of your required fields which is mandatory while processing the operations like insertion or updation of a record in your Database. May be you can have the look at it. If everything works well then try the following settings to the header of your request.

If your submitting the form with files then use the header's content-type as

  1. 'multipart/form-data',
  2. without files means then set the content-type as 'application/x-www-form-urlencoded',
  3. If you need to post the json means then set the content-type as 'application/json' and "Accept: 'application/json'"

If any cors error occurs then use 'crossDomain': true

var formData = new FormData();
axios.post('/api/addresses/upload/', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
})

Upvotes: 1

Related Questions