javascript timer to cgi

J

jason_box

Hello, I was wondering if there was a way to have a javacript be
activated by an input button that would call to a cgi program and
querey every 10minutes and the cgi would update the page without
additional user interaction. I found some timer stuff in js but it had
to do with delays and not what I was really looking for. Thank you in
advanced.
 
E

Evertjan.

jason_box wrote on 05 mei 2006 in comp.lang.javascript:
Hello, I was wondering if there was a way to have a javacript be
activated by an input button that would call to a cgi program and
querey every 10minutes and the cgi would update the page without
additional user interaction. I found some timer stuff in js but it had
to do with delays and not what I was really looking for.

But ....

CGI works on the server, and updating a page is done by the client.

The CGI programme cannot press a clientside button, so the user has to
presss it every 10 minutes?

Where do you want the javascript to run?

On the client browser, or on the server [under ASP]?

What is the difference between waiting and a delay?
Thank you in advanced.

Not that advanced I hope.
 
J

jason_box

Hello, Thank you for your quick response. I should clarify myself if my
question was a little confusion. The cgi script just calls to a local
server to output some data from the server which works. On the html
page I wanted a javascript that would be activiated and call the cgi
program and call to the cgi every 5-10minutes. The cgi will already
outputs the data to the main html page but I would like it to be only
active when a user wants the data. Since I do not want to over request
from the server, the javascript should just call to the cgi every
10minutes until the user press a stop button whcih cuases the
javascript to stop. I think this can be done with on() and off()
functions but I was not sure how to do this yet. The javascript will be
ran through the client side so of course it will require some
interaction. I hope this clears up any confusion. Thank you again.


Evertjan. said:
jason_box wrote on 05 mei 2006 in comp.lang.javascript:
Hello, I was wondering if there was a way to have a javacript be
activated by an input button that would call to a cgi program and
querey every 10minutes and the cgi would update the page without
additional user interaction. I found some timer stuff in js but it had
to do with delays and not what I was really looking for.

But ....

CGI works on the server, and updating a page is done by the client.

The CGI programme cannot press a clientside button, so the user has to
presss it every 10 minutes?

Where do you want the javascript to run?

On the client browser, or on the server [under ASP]?

What is the difference between waiting and a delay?
Thank you in advanced.

Not that advanced I hope.
 
E

Evertjan.

jason_box wrote on 05 mei 2006 in comp.lang.javascript:
Hello, Thank you for your quick response. I should clarify myself if my
question was a little confusion. The cgi script just calls to a local
server to output some data from the server which works. On the html
page I wanted a javascript that would be activiated and call the cgi
program and call to the cgi every 5-10minutes. The cgi will already
outputs the data to the main html page but I would like it to be only
active when a user wants the data. Since I do not want to over request
from the server, the javascript should just call to the cgi every
10minutes until the user press a stop button whcih cuases the
javascript to stop. I think this can be done with on() and off()
functions but I was not sure how to do this yet. The javascript will be
ran through the client side so of course it will require some
interaction. I hope this clears up any confusion. Thank you again.

[please do not toppost on usenet]


<button
onclick='var tmt = setInterval("doCallServer()",10*60*1000)'>
start</button>

<button onclick='clearInterval(tmt)'>
stop</button>
 
J

jason_box

<button
onclick='var tmt = setInterval("doCallServer()",10*60*1000)'>
start</button>

<button onclick='clearInterval(tmt)'>
stop</button>

Which part of the segment of code do I make the call to the cgi
program?
I was thinking of using general input forms and have it submit and post
to cgi, but that would still leave me with the timing issue.

Also on another note, on this line
onclick='var tmt = setInterval("doCallServer()",10*60*1000)'>

10*60*1000, what units is this in?

Thank you.
 
A

ASM

jason_box a écrit :
Which part of the segment of code do I make the call to the cgi
program?

you'll need to create your function doCallServer()

i.e : to submit your form nammed 'myForm'

function doCallServer() {
document.forms['myForm'].submit();
}
I was thinking of using general input forms and have it submit and post
to cgi, but that would still leave me with the timing issue.

The problem will be : on datas sent back from your cgi
the start button will have to be pushed again.
Perhaps could you send with theses datas some JS script to automatically
re-start the timer

<script type="text/javascript">
var tmt;
onload = function() {
tmt = setInterval("doCallServer()",10*60*1000);
}
10*60*1000, what units is this in?

milliseconds (here : 10 minutes)
 
R

Randy Webb

jason_box said the following on 5/4/2006 9:04 PM:
Which part of the segment of code do I make the call to the cgi
program?

In the doCallServer() function.
I was thinking of using general input forms and have it submit and post
to cgi, but that would still leave me with the timing issue.

No, setInterval sets that timer. Whether you had a timing issue or not
(and how you solved it) would depend on how you update the page.
Also on another note, on this line


10*60*1000, what units is this in?

milliseconds and should probably be hard coded as 600000 instead of the
browser doing multiplication every time.
 
J

jason_box

you'll need to create your function doCallServer()
i.e : to submit your form nammed 'myForm'
function doCallServer() {
document.forms['myForm'].submit();


I think I got a little confused with this. The javascript will handle
the timing of calling to the cgi script, so when the button is pressed,
it triggers the event to the cgi and the javascript can be made so that
it will call the script x-mount of minutes. Now I can see what the
doCallServer() would do, but I'm confused on why a
documents.form['myForm'].submit() would be needed? Wouldn't that mean I
have a form with data to pass to the cgi? In my case I have no data to
pass to the cgi, I only call to it and it does its job and I just need
to know the segment of code that will return the location of where the
output will be on the main index.html page. Thank you all again for
your time and explanations.
 
E

Evertjan.

Randy Webb wrote on 05 mei 2006 in comp.lang.javascript:
milliseconds and should probably be hard coded as 600000 instead of the
browser doing multiplication every time.

This multiplication is done only when clicked, so probably far less than
every 10 minutes. The setInterval() does not recalculate, but stores the
result, I presume.

For educational purposes, I prefer 10*60*1000 in this NG.

[As John Stockton so often remarked, 6e5 would be the best notation.]
 
A

ASM

jason_box a écrit :
you'll need to create your function doCallServer()
i.e : to submit your form nammed 'myForm'
function doCallServer() {
document.forms['myForm'].submit(); }

I think I got a little confused with this. The javascript will handle
the timing of calling to the cgi script, so when the button is pressed,
it triggers the event to the cgi and the javascript can be made so that
it will call the script x-mount of minutes.

I have a little problem with your deal :
"javacript be activated by an input button that would call to a cgi
program and querey every 10minutes and the cgi would update the page"
here ___________________________________________^^^^^^^^^^^^^^^^^^^^^

As I unterstand your cgi loads back same page (with some adds on?)
On each new load the previous Javascript is forgotten ... :-(

If you need a JavaScript to update sequentially a page, this page has to
be displayed in an other viewport (window or frame or iframe).

You may also use XMLHttpRequest to modify (on the fly) a part of your
page but this way of doing is not very easy, overall if you aren't
familiar with JavaScript.

ask XMLHttpRequest to Google
Now I can see what the
doCallServer() would do, but I'm confused on why a
documents.form['myForm'].submit() would be needed?

That is an answer to your precedent post where you talk about form.
Wouldn't that mean I
have a form with data to pass to the cgi? In my case I have no data to
pass to the cgi, I only call to it

To call it you need a button with an onclick or a link or an action's
form, no ?
and it does its job and I just need
to know the segment of code that will return the location of where the
output will be on the main index.html page.


<html>
<h1>my main page</h1>
<form>
<input type=button name="start" value="Start"
onclick="if(parent.myFrame)
tmp=setInterval('parent.myFrame.location=\'/cgi/foo.cgi\'',600000);
else alert('browser non compatible');
this.disabled=true;
stop.disabled=false;
">
<input type=button name="stop" value="Stop" disabled
onclick="clearInterval(tmp);
this.disabled=true;
start.disabled=false;">
</form>
<iframe name="myFrame" src="/cgi/foo.cgi" width=500 height=400>
Your browser doesn't know iframes, click <a href="/cgi/foo.cgi">here</a>
</iframe>
</html>
 
J

jason_box

Thank you all for your help. That XMLHttpRequest() object is very
useful and I also used document.getElementById().innerHTML function
to specify where I wanted outputted instead of using iFrames. I've had
issues with iframes in the past, but they were useful for a site I
built a year back. Thanks again, I got my script to work perfect now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top