Vue Resource - Post multiple data

Ricky Barnett picture Ricky Barnett · Feb 18, 2016 · Viewed 7.4k times · Source

I have the following:

bidAmount: {
    amount: 0
},
userToken: {
    token: null
},

this.$http.post('/place-bet', this.bidAmount, function(response) {
    alert(response);
});

How do I send both this.bidAmount and this.userToken

I have tried this however it doesn't send correctly:

this.$http.post('/place-bet', [this.userToken, this.bidAmount], function(response) {
    alert(response);
});

Answer

Jeff picture Jeff · Feb 18, 2016

You should always post an object, that way you can access the variables on the server using their respective keys:

this.$http.post('/place-bet', {userToken: this.userToken, bidAmount: this.bidAmount}, function(response) {
    alert(response);
});

or...

this.$http.post('/place-bet', {data:[this.userToken, this.bidAmount]}, function(response) {
    alert(response);
});