Displaying Ajax data and using timers properly

S

shawnwperkins

Hi Guys,

I'm new to Javascript and have a couple of questions that I hope
someone could quickly answer for me.

First, I'm trying to modify an example Ajax script to fit my needs.

The script is located here:

http://ajaxify.com/run/time/periodicRefresh/

I'm trying to display return data from my existing script, and I'm a
little confused on how to display the returned variables within my Web
page. Currently the author of the 'example' script has the following
code embedded within the HTML:

<form action="/">

<div id='customTimeLabel' class='timeLabel'></div>

<div align="center">
<input type="hidden" id="customTime" value="Refresh" />
</div>

</div>
<div align="center"></div>

</form>

The author displays this form and also has a button to create an
additional action when the button is pressed. I removed the button and
just want to display the variables, I do not want to have a form as he
did. Is there a alternate way of doing this? When I embed this in my
code it takes up too much real estate on the Web page.


Second, there is a setInterval timer used that periodically goes to
the server and refreshes the data. I have created a function,
'volup()' that stops the timer 'clearInterval(interval)' and displays
a new message for a few seconds, then my script is supposed to restart
the setInterval timer. Everything seems to work ok with the exception
of the setInterval restart. Could someone have a look at my code and
give me some suggestions? The problem is on the last line of the
volup() function, this command never seems to restart the timer. Also
I've noticed that my setTimeout timer can become very erratic at
times, not following my specified timing of 3 seconds, but this only
happens once in a great while and is very intermittent.

Thanks in advance,

Shawn


ajaxCaller.shouldDebug = false;
var timeURL = "cgi-bin/test?h=1";
//var timeURL = "tickercontent.txt";
window.onload = function() {
// $("defaultTime").onclick=requestDefaultTime;
// $("customTime").onclick=requestCustomTime;
requestCustomTime();

interval=setInterval(requestCustomTime, 1500);
}

function volup(){

clearInterval(interval)
showCustomTime("Change Source", "");

a="requestCustomTime();"

setTimeout(a, 3000);
clearTimeout(t)

interval=setInterval(requestCustomTime, 1500)

}

function requestCustomTime() {
var callingContext = Math.round(Math.random() * 100);
ajaxCaller.getPlainText(timeURL, showCustomTime);


}

function showCustomTime(text, callingContext) {
var customTimeLabel = $("customTimeLabel");
customTimeLabel.innerHTML = text + "." + callingContext;
}
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top