how to cancel/abort ajax request in axios

前端 未结 8 686
广开言路
广开言路 2020-12-05 06:19

I use axios for ajax requests and reactJS + flux for render UI. In my app there is third side timeline (reactJS component). Timeline c

8条回答
  •  伪装坚强ぢ
    2020-12-05 06:43

    This is how I did it using promises in node. Pollings stop after making the first request.

     var axios = require('axios');
        var CancelToken = axios.CancelToken;
        var cancel;
        axios.get('www.url.com',
                          {
                            cancelToken: new CancelToken(
                                function executor(c) {
                                    cancel = c;
                                 })
                          }
                ).then((response) =>{            
                    cancel();               
                  })
    

提交回复
热议问题