Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with Perl/Javascript
by Gangabass (Vicar) on Aug 07, 2007 at 09:10 UTC | |
| [reply] |
| |
|
Re: Help with Perl/Javascript
by Burak (Chaplain) on Aug 07, 2007 at 19:47 UTC | |
| [reply] [d/l] [select] |
|
Re: Help with Perl/Javascript
by NetWallah (Canon) on Aug 07, 2007 at 19:58 UTC | |
Please note : There seems to be an updated, and better documented version of the javascript at the author (Balamurugan S)'s website (http://www.sbmkpm.com/). "An undefined problem has an infinite number of solutions." - Robert A. Humphrey "If you're not part of the solution, you're part of the precipitate." - Henry J. Tillman | [reply] [d/l] |
|
Re: Help with Perl/Javascript
by scorpio17 (Canon) on Aug 07, 2007 at 19:30 UTC | |
Here's a working demo that should help you get started. First, here's the html part:
This html code contains one javascript function, getpic(). The body tag contains an onLoad event. This means that getpic() will get called as soon as the page loads. There is a single img tag. The default image (loading.gif) should simply be the text "loading...". You can make that yourself. Note that the img tag also has an id (pic_id) - this is to make it easy to find inside our javascript code. Its value would be more obvious if the page had dozens of other images! Note that the src attribute of the img tag points to the source of the image we want to display. If we change this, we change the image on the web page. As soon as getpic() runs, it changes the src attribute of the img. The src can be any valid url that returns image data. Normally, this is a file, but it can also be a cgi-script. In this case, test_gd.pl spits out random gifs, generated using the GD.pm module. The setTimeout() function is used to run getpic() again, after a 2000 ms delay. So - every two seconds, the script will reload the image. In a real application, the perl script would be delivering plots of the latest data each time. You wouldn't necessarily have to use GD.pm, but if you're making simple charts of data, it's pretty useful. The test_gd.pl script I used is really just for demo purposes, but the code for it looks like this:
Note that this is almost exactly like the example shown in the GD.pm POD file - I just changed the output file type to gif, and make the color of the circle random (red, green, or blue). Note also that you have to print out the appropriate content type (image/gif). Finally, note that I use the javascript Date object, and the getTime() method to fetch the integer number of seconds since the beginning of time, and add it to the url. Bascially, this makes each url unique, and thus prevents the browser from caching only one copy of the image. If it did, you wouldn't ever see the updates. This may not be necessary with all browsers. I hope this helps you. Good luck! | [reply] [d/l] [select] |
|
Re: Help with Perl/Javascript
by Anonymous Monk on Aug 07, 2007 at 09:11 UTC | |
| [reply] |