If you need to call a server process at regular intervals in your web page then this is actually a simple task that requires only a few lines of code and a little Ajax fun.
In this tutorial I will show you how to create a page to display the current system time. It will show you the principles of how to perform this operation so you can then use it in your own web apps.
I firstly created a Dynamic WebDev App and added a page. On the page I added a Cell component and inside a Static Control which will display the time.
We are not going to be using any JavaScript for this, just some simple WL. Firstly we need to add a Timer to the browser load event.
Now remember this code is executed in the browser and not on the server so make sure you choose the correct event.
The code will call a WL method called CheckTheTime every second. You need to create a New Local Browser Procedure which the timer will call.
This is one of many things I love about WebDev, making AJAX calls is such a breeze. So the code above will call a method on the server which will return the current system time as a string.
So now create a new Local Procedure (server side procedure) called GetTime. As you are making an AJAX call to this method you have to enable it to allow this type of action. Once again this is very simple, just click on the AJAX word at the top next to the method and the LED light will go green to show it has been enabled.
Then all you have to do is write the code which returns time time.
That’s it, you are done. Running the page will now display the current time and will automatically refresh every second.















Recent Comments