I
I
Intelix2022-03-07 13:27:27
Vue.js
Intelix, 2022-03-07 13:27:27

Why Cannot POST when sending data via axios?

I want to send data from the form to the server

formSubmit: function () {
  let resultData = JSON.stringify(this.formData)
  axios.post('https://Домен/api/tasks/create.php', {
    data: resultData
  })
      .then(response=>{
        console.log(response);
      })
      .catch(error=>{
        console.log(error);
      })
}


formdata looks like this:
formData: {
    name: "Alex",
    geo: "Ru",
    executor: "1",
    complexity: "1",
    deadline: "2022-03-07 12:20:22",
  },

But when you call the formSubmit (@submit="formSubmit") method, this appears on the screen.

Cannot POST / here is the name of the view component.

Sent the same data to the same url via Postman, everything is fine.

Why Cannot POST, how to fix it?

upd tried again like this, indicating the content type, but the same problem
formSubmit: function () {
      let resultData = JSON.stringify(this.formData)
      axios({
        method: 'post',
        url: 'https://домен/api/tasks/create.php',
        data: resultData,
        headers: {
          "Content-type": "application/json"
        }
      })
          .then(function(response) {
            console.log('Ответ сервера успешно получен!');
            console.log(response.data);
          })
          .catch(function(error) {
            console.log(error);
          });
    }

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