Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
    });
Comment

Axios FormData / not 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);
  });
Comment

axios post form data and 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);
    });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: uncaught TypeError: $.jajax is not a function 
Javascript :: react environment 
Javascript :: queryselectorall data attribute 
Javascript :: To split a full name into first and last names in JavaScript 
Javascript :: copy variable value javascript 
Javascript :: lodash convert object to array 
Javascript :: node js variables in string 
Javascript :: jquery siblings 
Javascript :: js cut string after last char 
Javascript :: scrollbar automatically scroll down as new divs are added reactjs 
Javascript :: find all checkbox inside div jquery 
Javascript :: send mail with javascript 
Javascript :: regex for check if string is only empty or whitespace javascript 
Javascript :: postmessage from iframe to parent 
Javascript :: placeholder javascript 
Javascript :: moment timezone get timezone offset 
Javascript :: fullcalendar v5 time format am/pm 
Javascript :: check data type in javascript 
Javascript :: react copy to clipboard button 
Javascript :: get first day of the week of a given date javascript js 
Javascript :: mat checkbox change event in angular 7 
Javascript :: useeffect hook react 
Javascript :: javascript remove underscore and capitalize 
Javascript :: check value exist in array javascript 
Javascript :: js get current timezone offset 
Javascript :: adding border in react native 
Javascript :: moment get weekday name 
Javascript :: js weakset 
Javascript :: today date javascript 
Javascript :: is check objet empty 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =