I am using javascript and Node JS to build a website to collect data for my writing research. The website is designed with a series of webpages with each page housing a different typing or writing task. Participants need to complete a task on one page, click the submit button to post the data to the server side, and click next to move on to the next page until they reach the last page of the study. For your information, here is the website I created: https://writingresearch.herokuapp.com.
However, here comes one issue: in some cases, when the internet connection on the client side is weak or unstable, it might take some time (say, more than 2 seconds) for the data to reach the server side for processing. In other words, the participant of the study may go to the next page before their posted data are successfully processed on the server side. If this happens, the server side ends up losing the data.
Thus, I am wondering if there is a method to enable the communication between the server side and the client side so that the user of the website cannot go to the next page until their post request is successfully processed. Does anyone know how to do this in Node JS? I hope I have explained my question clearly.
Thanks for your time and attention. I really appreciate your help!!!
On pressing the submit button, you should do the following:
Disable the "Submit" button so that user doesn't send another POST request again by clicking on submit button again. Show a loader somewhere so that user could know that answer is being submitted.
Disable the "Next" button until you receive a successful response from server.
On receiving successful response from server, enable both buttons and show a notification (such as an alert box) informing that the answer is submitted successfully.
If you receive error from server, then also show the error in the notification (or in the alert box) and enable both buttons.