Online status board
Alex Tweedly
alex at tweedly.net
Wed Nov 18 19:09:53 EST 2009
Jan Schenkel wrote:
> Well, in the AJAX world, you would write a JavaScript that sends an XmlHttpRequest every couple of seconds, and modifies the existing web page. But we're in a revCentered world here, so let's take the other route :-)
>
> Along the same lines, you could make a revlet that uses 'get url' and 'post to url' commands in a 'send in time' loop to interact with the server back-end, and update the user interface with the changes. If your server back-end can send the information in XML or JSON format, you can still decide later on to make an AJAX-style front-end.
>
Just to be specific about this, I wrote a very simple test revlet for this
- two buttons called start and stop
- two fields called "time" and "field"
- and the following card script
built a revlet, and it works fine - changes to the text file are
displayed promptly. Just change the url name to something you can
control and try it out.
NB - if doing this for real, I'd make the text file contain the time of
last change (i.e. saved to the file whenever the server app makes an
update), then have the revlet check if this has changed since the last
time it retrieved the resources data, and only if it has changed would
you download the rest of the data. If you do something like that to make
sure the periodic download is small (and assuming you don't expect large
numbers of clients at any time) then you could keep the period small
(e.g. one second, or a few seconds) and probably obviate the need for
pushing data.
> local sGoing
>
> on mouseup
> if word 1 of the target = "button" then
> put char 2 to -2 of word 2 of the target into tButtonName
> if tButtonName = "start" then
> put true into sGoing
> send "startgoing" to me
> end if
> if tButtonName = "stop" then
> put false into sGoing
> send "stopgoing" to me
> end if
> end if
> end mouseup
>
> on readnext
> put the millisecs into field "time"
> put URL ("http://www.maelstroma.co.uk/a.txt") into field "Field"
> if sGoing then
> send readnext to me in 1000 millisecs
> end if
> end readnext
>
> on startgoing
> put true into sGoing
> send "readnext" to me
> end startgoing
>
> on stopgoing
> put false into sGoing
> end stopgoing
-- Alex.
More information about the use-livecode
mailing list