I am a beginner to web applications. I am confused what is “the best way” to accomplish what I am doing and I would appreciate some help in making choices.
I am developing an application (helping a friend) that does something like this.
There will be two buttons on the page (used Bootstrap).
Users may click them randomly.
Whenever they click, random numbers are generated by Javascript. (used jQuery)
User clicks the Submit Button.
His sequence of clicks, time of clicking, duration between clicks and the random numbers generated should be stored in the database.
My questions :
(A) Should I use AJAX to update the database then and there, when the button is clicked ?
Or
(B) Should I keep appending the value to a Javascript array/JSON string/HTML hidden textbox as and when they click and finally update the database on submission ?
Note : I am aware that if I don’t use AJAX and user chooses to move away after a few clicks without hitting the Submit button, all data may be lost. My friend says thats okay if the user wishes to consciously move away.
If I should use Option B, further questions :
B1. Which one should I use : A javascript variable, JSON string or HTML hidden textbox ? (Is it possible to append data to a Javascript array variable ?)
B2.
(i) Should I send the entire JSON string to a MySql stored procedure and let it handle the parsing and inserts ?
Or
(ii) Should I build all the insert statements into a single SQL string and submit it ?
Or
(iii) Should I do the inserts as I loop through the values for each click ?
Any other methods welcome too.