Axios params not appending correctly to URL

2.9k Views Asked by At

I'm trying to use params for a post request using Axios. However, when I check the XHR in Chrome, the params don't seem to be appended to the URL.

If I do this, it works:

axios.post('/!/Like/like?id=' + this.id + '&_token=' + this.csrf_token)

But if I try this, I get an error:

axios.post('/!/Like/like', {
    params: {
        id: this.id,
        _token: this.csrf_token
    }
})

In other words, the url needs to be:

/!/Like/like?id=1234&_token=zYXW-123

Any ideas what I might be doing wrong?

1

There are 1 best solutions below

11
On BEST ANSWER

The second parameter in axios.post is the data. If you wanted to post the way you are doing here, you would need to pass your params as the third argument.

axios.post('/!/Like/like', "", {
    params: {
        id: this.id,
        _token: this.csrf_token
    }
})