-1

I'm sure this is a SUPER noob question, but I'm having trouble finding resources which detail simple client-side server-side interactions.

I've got a webpage where clicking a button uses a little JavaScript to increment a counter by one. Naturally when the page is refreshed, the number resets.

How could I set up some simple backend or database that instead will save the number and call it back the next time the page is loaded?

Lachy Vass
  • 51
  • 1
  • 6
  • This is too broad for Stack Overflow. Please read about what's on-topic in the [help/on-topic]. You would be better off picking a technology (that's up to you) and searching for a tutorial. – ChrisGPT was on strike Jun 28 '17 at 11:49
  • We assume you want to show this to other users of the web site? If not, then use a cookie of localStorage – mplungjan Jun 28 '17 at 11:51
  • you know you will probably get down votes for this question right? Edit the Question! What framework did you use to build your site? Is that local development or in Production? – hansTheFranz Jun 28 '17 at 11:51

2 Answers2

0

use localstorage to save the number https://www.smashingmagazine.com/2010/10/local-storage-and-how-to-use-it/

Rishabh Mishra
  • 498
  • 8
  • 21
0

The simplest way would be to use HTML5 Web Storage (LocalStorage) to store it and load it with Javascript on page load. Each client/browser will have its own version of the storage so you won't be able to load the same number across multiple devices. For this you could use SQLite or any other database engine.

HTML5 Web Storage: https://www.w3schools.com/html/html5_webstorage.asp

laurentius
  • 1,093
  • 1
  • 9
  • 20