This is a job for AJAX. Instead of using document.location to redirect to another page, what you need to do is:

  1. Create an XMLHttpRequest object.
  2. Use that object to make a request (i.e., invoke your perl cgi script).
  3. Define a response handler that will receive the output of your script and insert it into your page, you can create an empty div element to act as a placeholder for this.
  4. After handling each response, setup the next request (this is how you would loop through all your dates)

Here's a simple demo I had laying around that does something similar:

<html> <head> <script type="text/javascript"> function createRequestObject() { var req; if (window.XMLHttpRequest) { // Firefox, Safari, Opera... req = new XMLHttpRequest(); } else if (window.ActiveXObject) { // Internet Explorer 5+ req = new ActiveXObject("Microsoft.XMLHTTP"); } else { // error creating the request object, // (maybe an old browser is being used?) alert('There was a problem creating the XMLHttpRequest object'); req = ''; } return req; } // Make the XMLHttpRequest object var http = createRequestObject(); sendRequest(); function sendRequest() { // Open perl script for requests var now = new Date(); http.open('GET', 'http://' + document.domain + '/cgi-bin/ajax/demo. +pl?nocache='+now.getTime(), true); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4 && http.status == 200){ var response = http.responseText; // Text returned FROM perl scrip +t if(response) { // UPDATE ajaxText content document.getElementById("ajaxText").innerHTML = response; setTimeout('sendRequest()', 5000); } } } </script> </head> <body> <p>The message is...</p> <div id="ajaxText" >Hello World!</div> </body> </html>

This is just a demo. The demo.pl cgi script simply prints out a random text string:

#!/usr/bin/perl use strict; print "content-type: text/html\n\n"; my @messages = ( "This is message 1", "This is message 2", "This is message 3", "This is message 4", "This is message 5", ); # print a random message print @messages[rand @messages] , "\n";

The response handler calls this script every 5 seconds using setTimeout(). Note that I append the epoch time to the cgi script query string so that the browser won't simply cache the first response and use it over and over (that's a common ajax gotcha). When you view the html page in your browser, you should see the message change randomly every 5 seconds.

I hope that helps get you moving in the right direction. Good luck!


In reply to Re: How to simulate? by scorpio17
in thread How to simulate? by isi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.