开发者

How to refresh parts of page when database changes?

开发者 https://www.devze.com 2023-04-10 07:49 出处:网络
I want a better way to update images on a webpage instead of forcing the webpage to refresh every 60 seconds.

I want a better way to update images on a webpage instead of forcing the webpage to refresh every 60 seconds.

I wrote a little status page that monitors some of our web sites. It uses web.py and displays a list of servers I have inputted into a database.

Each server that is up gets a Green png image displayed next to it.

When a server开发者_JAVA技巧 goes down I update the status in a local mysql database to false.

The next time the page refreshes it gets a red png displayed next to it.

Right now that red png file does not display until I refresh the page.

Is there a way in web.py (python) that I can make just that image dynamic without having to refresh the whole page? Or do I have to use something else to make it work?


Well, the generic answer is that you use AJAX and put a script on each server that will return "up" or something every time your page checks.

Here's a tutorial on how to do AJAX with web.py specifically: http://kooneiform.wordpress.com/2010/02/28/python-and-ajax-for-beginners-with-webpy-and-jquery/


I have no knowledge related to web.py.

But in my point of view what you gonna need is to break your code in two parts (a monitor service and a monitor display) and use javascript to asynchronously update the data.

Your monitor service will provide a url that receives the monitored site ID and returns up or down. As you are using web.py, it will probably be 100% python.

Your monitor display will use javascript to ever X seconds checks that url and show the correct icon. It can be python based, or not. But it will need javascript.

0

精彩评论

暂无评论...
验证码 换一张
取 消