“Axios Post Form Data dan JSON” Kode Jawaban

Axios Post Formdata

axios({
    method: 'post',
    url: 'myurl',
    data: bodyFormData,
    headers: {'Content-Type': 'multipart/form-data' }
    })
    .then(function (response) {
        //handle success
        console.log(response);
    })
    .catch(function (response) {
        //handle error
        console.log(response);
    });
florinrelea

AXIOS FORMDATA / BUKAN JSON

var bodyFormData = new FormData();
bodyFormData.append('userName', 'Fred');

If you are uploading images, you may want to use .append
bodyFormData.append('image', imageFile); 

axios({
  method: "post",
  url: "myurl",
  data: bodyFormData,
  headers: { "Content-Type": "multipart/form-data" },
})
  .then(function (response) {
    //handle success
    console.log(response);
  })
  .catch(function (response) {
    //handle error
    console.log(response);
  });
Delightful Donkey

Axios Post Form Data dan JSON

doAjaxPost() {
    var formData = new FormData();
    var file = document.querySelector('#file');

    formData.append("file", file.files[0]);
    // formData.append("document", documentJson); instead of this, use the line below.
    formData.append("document", JSON.stringify(documentJson));

    axios({
        method: 'post',
        url: 'http://192.168.1.69:8080/api/files',
        data: formData,
    })
    .then(function (response) {
        console.log(response);
    })
    .catch(function (response) {
        console.log(response);
    });
}
Evil Echidna

Jawaban yang mirip dengan “Axios Post Form Data dan JSON”

Pertanyaan yang mirip dengan “Axios Post Form Data dan JSON”

Lebih banyak jawaban terkait untuk “Axios Post Form Data dan JSON” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya