Reputation: 164
i am working on a vue / laravel project and i want to send an array and formdata with axios .
this is my code:
submit(){
//The FormData
const formData = new FormData
formData.set('images', this.imagesInfo)
//The Array
this.product ={
data: this.data,
option: this.option
}
//How can i send *this.product* and *formData* ?
axios.post('/admin/product/add', ****)
}
How can i send this.product and formData with axios?
Upvotes: 0
Views: 1841
Reputation: 5844
In form data, you can't send array directly.
In order to send array in formdata
you have to run a loop
and pass values like this:
const array = [1,2,3,4,5,6];
const formData = new FormData();
array.forEach(function(value) {
formData.append("id[]", value) // you have to add array symbol after the key name
})
Upvotes: 3