Welcome to the realm of server-side IT.
There are several ways to do this:
AJAX from W3Schools.com OR
Application Markup Language
You’re at a point that you need to start learning server-side (i.e., “infrastructure” ) middleware … such as PHP, ASP, .NET, PYTHON, and (the list goes on) …
Unfortunately, all these technologies are migrating toward Cloud Service, DevOps, and Server-less environments. Yes, you still need to understand “middle-ware” to use any of them.
I would suggest “where to start and how to begin” with this chart … BUT I’M ALWAYS DELETED FROM THIS FORUM FOR MY HELPFUL SUGGESTIONS. I recommend a quick google search on “Headless HTML5 Game Design” or “Making RPG Browser Games Content-as-a-Service” .