By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,882 Members | 2,465 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,882 IT Pros & Developers. It's quick & easy.

Displaying Ajax data and using timers properly

P: n/a
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;
}

Sep 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 2008-09-28 01:32, sh***********@gmail.com wrote:
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>
Then he should go and validate his code, I'd say...

The kind of question you're asking is not much fun to answer, I'm
afraid. We're supposed to debug somebody else's library, which has been
modified, and now it doesn't work anymore. It would be a lot easier if
you could sort of ask a more contained question.
ajaxCaller.shouldDebug = false;
I don't know anything about ajaxCaller. Maybe shouldDebug can help?
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)
What's "t"?
interval=setInterval(requestCustomTime, 1500)
So, in three seconds, requestCustomeTime will be called twice? Once from
setTimeout() and once from setInterval(). That might explain the
"erratic" behavior.
- Conrad
Sep 28 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.