Image for post
Image for post

Handle duplicate HTTP calls in the axios interceptors

To handle the duplicate Ajax request, we could simply define a loading variable for button actions, which contains the state of the ajax request. When the user clicks the button and triggers the RESTful api call action, set the loading variable to true and disable the button regarding on it. After we received a response or error then set the loading variable to false so that no duplicate request will trigger through the button click.

A nice thing about handle duplicate HTTP calls in the axios interceptors is that they can generally handle it and prevent unpredictable results even if you have custom control on the loading state for user action. …

About

Wiky Cheng

www.wikycheng.com — Full stack web developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store