Search code examples
vue.jsvue-resource

Vue Resource - Post multiple data


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);
});

Solution

  • 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);
    });