View Full Version : Ajax refresh problem

09-21-2008, 09:30 PM
1) Script Title: Ajax XML Ticker (txt file source)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex2/ajaxticker.htm

3) Describe problem:

Hello Folks,

I'm a newbie to Ajax, and just have a quick question. I'm using the Ajax XML Ticker above and it works great. However I would like to have the script go and fetch an update of the XML file at a given interval, say every five seconds and refresh the display with the new data. I have tried everything that I can think of, but cannot seem to get this to work.
It would appear that I need to call this.getXMLfile() every so often, but I have not been successful.

Any help or suggestions would be greatly appreciated.


09-22-2008, 04:54 AM
This is more of a feature request than problem. I may eventually add such an ability to the script; in the meantime, the best I can do is give you an idea of how to do this. Firstly, replace the original rotatemsg() function inside the script with the below instead:

var instanceOfTicker=this
if (this.mouseoverBol==1) //if mouse is currently over ticker, do nothing (pause it)
this.pausetimer=setTimeout(function(){instanceOfTicker.rotatemsg()}, 100)
else{ //else, construct item, show and rotate it!
this.fadetransition("reset") //FADE EFFECT- RESET OPACITY
this.fadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'fadetimer1')}, 100) //FADE EFFECT- PLAY IT
this.pointer=(this.pointer<this.messages.length-1)? this.pointer+1 : 0
this.rotatetimer=setTimeout(function(){instanceOfTicker.rotatemsg()}, this.delay) //update container periodically

The parts in red are now, basically adding identifiers to the timers used by the function, to cancel them before refreshing the script. Then, for the script on your HTML page itself, you may have something like:

<script type="text/javascript">

var xmlfile="tickercontent.txt" //path to ticker txt file on your server.

//ajax_ticker(xmlfile, divId, divClass, delay, optionalfadeornot)
var myticker=new ajax_ticker(xmlfile, "ajaxticker1", "someclass", 3500, "fade")

<script type="text/javascript">

function updatesource(){
document.getElementById(myticker.tickerid).firstChild.innerHTML="refreshing contents..."

//refresh ticker source every 4 seconds
setInterval("updatesource()", 4000)


09-23-2008, 03:15 AM
Dear ddadmin,

I appreciate you taking time out of your busy schedule to give me some great ideas to point me in the right direction. Unfortunately I'm under the gun and need some additional help with customization. I noticed that you have a forum for folks that are willing to pay for additional assistance. I will post what I need to have, and will also pay you for your time already spent as well as any other time needed if you could fit me in to your schedule. My deadline is late Wednesday evening on this one :)

Thank you again, you are a lifesaver!!


09-23-2008, 07:32 AM
Hi Shawn:
You're welcome, though due to my current very hectic schedule, I personally can't take on your paid request. Hopefully another senior member will be willing to take a stab at it. If you're really under a very tight timeline, you may also want to consider reposting your request on a dedicated freelancer type site such as Elance.com or Getafreelancer.com.

Sorry for not being able to help you myself.