Siyah Papyon
Siyah Papyon

Reputation: 3

How can I post two objects simultaneously with axios?

I have a problem like this; I want to post two objects at the same time with axios, but I realized that it is not with the following codes. How do you think I can post two objects at the same time?

let companyAry = this.toFormData(this.company[0]);
let productsAry = this.toFormData(this.basket[0]);

axios.post('http://localhost/post', companyAry, productAry)
.then(response => {
  console.log(response.data.message);

});

Upvotes: 0

Views: 1411

Answers (2)

Ardahan Kisbet
Ardahan Kisbet

Reputation: 659

You can combine company and basket objects to one parent object.

let params = {
    companyData: companyAry,
    productData: productAry
  }

let res = await axios.post('your url in here', params);

Upvotes: 1

David
David

Reputation: 16277

Try this:

var output = Object.assign(companyAry, productsAry );

Upvotes: 0

Related Questions