vue axios post how to submit formdata array?

I need to submit an ARRAY data because the backend can only recognize such data

Expected effect:

&row[weigh]=0
&row[status]=normal

code:

row:{
  weigh: 0,
  status: 'normal'
}

actual effect:

row:{
  weigh: 0,
  status: 'normal'
}

When I submit the data, the console displays JSON instead of Array, but the backend cannot get it

What I need is to be consistent with the results from the form submission below

<form  method="POST" >
  <input name="row[a]" type="text" value="">
  <input name="row[b]" type="text" value="">

Try this code.

let row = {
  weigh: 0,
  status: 'normal'
};

let finalArr = [];

Object.keys(row).forEach((key) => {
    finalArr.push(`row[${key}]=` + row[key]);
});
console.log(finalArr.join('&'));
// outputs: row[weigh]=0&row[status]=normal

Vue Axios Post Request Example, we will send post request with parameter as array or form data in vue cli npm app . here will be simple example of axios post request in vue js app� In this post, we will lean how to send http request using axios in vue js. we will send post request with parameter as array or form data in vue cli npm app. here will be simple example of axios post request in vue js app from scratch. we always choose axios to call api in vue js application.

public register(rowObject: RowObject): AxiosPromise<any> {
    return axios.post('http://localhost/api/register', rowObject);
}

This way you can pass the data in Post method.

rowObject =  {
    weigh: 0,
    status: 'normal'
    }

Axios POST Multipart Formdata object attribute, Posting some text or raw html works fine, but as soon as I try to post an image (or recognize the formData, when I dump the request it shows an empty array. So, if you want to send an array as you say, you should send axios.post ($ {API_URL}/company/uploadProducts, formData.products, header), --> formData.products is the array you are talking about. Then of course your backend must be able to handle an array instead of an object (JSON) otherwise it will "crash". – dnhyde Jul 27 '18 at 9:59

Your code also should pass an array just like this.

data = [
  {weigh: 0},
  {status: 'normal'}
]

then when you send it to server for example using axios, your code should look like this

axios.post('/api endpoint', {row:data})
    .then(response => {
     // response here
});

Using array form data array in Vue , not working when I compile on , Using array form data array in Vue , not working when I compile on webpack . Posted 'image 3'); // then I send the value with vue axios.post('myurl.com', data) . In network tab it also an empty post object, in my vuex module I console log the formdata entries and it’s there. JamesThomson 3 December 2018 03:20 #4

ok

const formData = new FormData()
  Object.keys(this.form).forEach(e => {
  formData.append(`row[${e}]`, this.form[e])
})

vuejs axios post form-data Code Example, Get code examples like "vuejs axios post form-data" instantly right from your google <button type="submit" name="button">Submit</button> <?php function pre_r($array){ echo '<pre> print_r($array); echo</pre>>' � <?php� Using array form data array in Vue , not working when I compile on webpack . Posted 3 years ago by murilo Hello Guys , I have a code that is working fine in Vue , but when I compiled it on Webpack , is not working properly any more .

axios post array data, we will send post request with parameter as array or form data in vue cli npm app . here will be simple example of axios post request in vue js app from scratch. The most concise screencasts for the working developer, updated daily. There's no shortage of content at Laracasts. In fact, you could watch nonstop for days upon days, and still not see everything!

Sending Images store in javascript array to server using , But I don't know why I am getting empty array. uploadImage.php?action=save", formData) .then(function(res){ console.log(res) }); } else { break; } } } You send axios request with post method and try to access data from get� in this example we will use axios for ajax api request and send form data in vue app. you can see bellow full example. in this example, we will create simple form with two input fields in vue js app. then we will form submit request by using axios http post request with following input parameter.

Issue with posting FormData with axios, Hi everybody, I want to send a file with FormData to my backend, however I'm getting an empty object when I inspect the request body. The two formats we will use to send data to the server is through JSON and application/x-www-form-urlencoded. By default Axios sends any data to the server as JSON. In most cases, this is fine. However, when you wish to upload a file, you will need to send the data as application/x-www-form-urlencoded.

Comments
  • Please add some explanation to your answer by editing it such that others can learn from it