I have a JavaScript application that regularly saves new and updated data. However I need it to work on slow connection as well.
Data is submitted in one single HTTP POST request. The response will return newly inserted ids for newly created records.
What I'm finding is that data submitted is fully saved, however sometimes the return result times out. The browser application therefore does not know the data has been submitted successfully and will try to save it again.
I know I can detect the timeout in the browser, but how can I make sure the data is saved correctly?
What are some good methods of handling this case?
I see from here https://dba.stackexchange.com/a/94309/2599 that I could include a pending state:
- Get transaction number from server
- send data, gets saved as pending on server
- if pending transaction already exists, do not overwrite data, but send same results back
- if success received, commit pending transaction
- if error back, retry later
- if timeout, retry later
However I'm looking for a simpler solution?