2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-05 16:42:32 +03:00

add example of cancelling a POST request to readme

it seems when cancelling a post request we need to specify cancellation token as an axios parameter and not as a data item.
This commit is contained in:
Nero
2018-01-22 13:00:21 +00:00
committed by GitHub
parent 138108ee56
commit c51054f24d
+23
View File
@@ -525,6 +525,29 @@ axios.get('/user/12345', {
source.cancel('Operation canceled by the user.');
```
```js
var CancelToken = axios.CancelToken;
var source = CancelToken.source();
axios(
method: 'POST',
url: '/user/12345',
data: {
name: 'new name'
},
cancelToken: source.token
}).catch(function(thrown) {
if (axios.isCancel(thrown)) {
console.log('Request canceled', thrown.message);
} else {
// handle error
}
});
// cancel the request (the message parameter is optional)
source.cancel('Operation canceled by the user.');
```
You can also create a cancel token by passing an executor function to the `CancelToken` constructor:
```js