0

As a non webdev, I'd really like if you could point me out to the 'correct' way to do this.

I built an application that populates and updates a database periodically (sqlite to be precise). I store leaderboards in my database, and would like to display them in a webpage.

As my leaderboards can change all the time, I need the webpage to be dynamic, either on a time based trigger or whenever the database changes.

I was about to use javascript for that, by realized that my database is hosted on my server, so client side js might not work.

Any ideas on that?

As my app is built in Python, I'd prefer avoid using php solutions but use more 'trendy' technologies (js, ruby, python, ? ? ? whatever)

Thanks!

Ok, given the keywords I got now here is an almost exact duplicate : Notify user on database change? JavaScript/AJAX

1
  • OP here. It's beautiful sometimes coming here later seeing how much I've learnt :). Much of it thanks to SO right there. Here's to daily learnings! Commented Feb 13, 2023 at 13:48

3 Answers 3

2

This is what Ajax is for. You write Javascript on the front end that uses Ajax to call your server-side code to return the database content, then updates your HTML when it receives a response.

Sign up to request clarification or add additional context in comments.

2 Comments

argh, yet another layer between my app and my user :s. Would you use AJAX directly, or through a framework or something ?
If you're completely new to it, probably better to use something like jQuery which takes care of some of the complexities.
1

You need to use javascript on the client side not on the server. Your javascript code will make async calls (using ajax) to check if the db changed and update the website accordingly.

Comments

0

You can either use javascript to poll the server side periodically. Or you can use javascript to create (perhaps using a library like SockJS or SocketIO) a websocket connection that can actually push data to the client side when it changes. I do this on a number of projects using Tornado's websocket support on the server side.

2 Comments

Sorry to bother, will creating a WebSocket for each user use up more resource than letting the client poll. What's the pros and cons for the two methods?
More resources, it keeps a socket open on the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.