Axios randomly sends duplicate POST request
See original GitHub issueDescribe the bug
axios.post
randomly sends duplicate POST request and ignores the first response.
The code is below:
class SomeClass extends React.PureComponent
isReady = true
submitCounter = 0
lastSent = null
// ...
submit() {
this.submitCounter++;
if (!this.isReady) {
return;
}
this.isReady = false;
this.setState({
isReady: false
});
const formData = new FormData();
formData.append("ts", Date.now());
formData.append("um", Math.random().toString(36).substr(2));
formData.append("ctop", this.submitCounter);
formData.append("lastSent", this.lastSent);
axios
.post(`https://someurl.here`, formData)
.then(({data}) => {
this.lastSent = dayjs().format("YYYY-MM-DD HH:mm:ss");
this.isReady = true;
this.submitCounter = 0
if (data.status === false) {
return;
}
this.setState({
isReady: true
});
})
.catch(err => {
console.log(error);
});
}
// ...
}
The submit function above is only called once, while the axios.post()
is called twice. I know it when I check the ts
, um
, ctop
, and lastSent
parameter are same with the previous record. Also, CPanel visitor record show that the request sent twice in short timespan.
Is it because the connection issues, or there are some configurations I missed? I already read the documentation, search Google and Stack Overflow, but still no clues about it.
To Reproduce I don’t know how to reproduce it since it’s randomly occurred.
Expected behavior The request is only sent once.
Environment:
- Axios Version: 0.18.0
- OS: Windows 7
- Browser: Chrome
- Browser Version: 75.0.3770.90
- Additional Library Versions: React 16.6.3
- Server: Laravel 5.7
- Database: MySQL 5.7
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:11
Top Results From Across the Web
How to avoid sending multiple duplicate AJAX requests in axios
It's quite easy to throttle an axios request call. The real headache is how to handle the promises that are returned from those...
Read more >Axios make double request to my server in my network tab
Any request i make axios make double of it my app.js import Axios from "axios"; window.axios = Axios; my component function submit(){ axios.post(RegUrl, ......
Read more >Axios sends a duplicate POST request in a Vue 3 (Vite) project
I'm having an issue with Axios sending a duplicate request to an API. 1st request without Bearer token header, 2nd request with the...
Read more >mzabriskie/axios - Gitter
I want to create an axios.response object use cached value inside request interceptor ... I've found that Axios randomly send duplicate POST request...
Read more >Axios in React Native - GeeksforGeeks
You can make both GET and POST requests with Axios in React Native: ... We will declare a function that randomly generates 1...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Closed due to lack of enough information.
Friendly to remind similar users, let’s open a new issue to describe your problem as detailed as you can, unless your problem is exactly the same with the thread author. It may looks like the same but totally different. And from readers’ side, we can’t learn something new from a simple reply that without replicable code example.
We’re seeing the same random problem, POST requests being sent twice sometimes
Environment: