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

How to send form data with Get method in axios?

//assuming instance is your axios instance.

instance.get("/test",{params:{key:value, key1:value1}}).then((data)=>{}).catch((error)=>{})

//this will send a GET request to /test?key=value&key1=value1

Comment

PREVIOUS NEXT
Code Example
Javascript :: reverse every word in a string javascript 
Javascript :: get current time in different timezone javascript 
Javascript :: js how to work with float 2 decimal numbers 
Javascript :: javascript check type of object 
Javascript :: javascript function to open file browser 
Javascript :: window.scrollto(0 0) not working 
Javascript :: vue mounted 
Javascript :: Uncaught TypeError: .replace is not a function 
Javascript :: express server 
Javascript :: javascript if string empty 
Javascript :: JavaScript read as Json 
Javascript :: js function string parameter 
Javascript :: last index of javascript 
Javascript :: chrome.storage.local get 
Javascript :: javascript last child 
Javascript :: router.push in vue 3 
Javascript :: javascript dynamic arrays 
Javascript :: javascript returning a function 
Javascript :: how to install vue 
Javascript :: javascript count no of lines 
Javascript :: js join 
Javascript :: javascript create element input type text 
Javascript :: @babel/plugin-proposal-optional-chaining 
Javascript :: nvm check version available to download 
Javascript :: javascript currency format 
Javascript :: display console log in HTML 
Javascript :: double click in js 
Javascript :: post method 
Javascript :: getdisplaymedia screenshot 
Javascript :: vscode 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =