Simple "slide show" suddenly skips several "slides" after a couple of run throughs

This is not actually a slide show in the accepted sense, but has a similar effect.

I have the following code to change the content of a div at regular intervals

<script type="text/javascript">
setInterval("refreshBlock()",20000);
    $.ajaxSetup({ cache: false });
    function refreshBlock()
    {      
       $('#content_block').load("ChangedContent.cfm");
     }
</script>

The code works fine, but after cycling through the content pages a couple of times (25 pages), every so often it will flick through 3 or 4 pages in rapid succession, then settle down again and stick to the 20 seconds per page for a while.

Any ideas why this is happening, and any way to stop the erratic behaviour?
LVL 3
jdthedjAsked:
Who is Participating?
 
RobOwner (Aidellio)Commented:
yep, was just a simple issue and I didn't say, just assumed, because $(function() {...}); is exactly the same as $(document).ready(function() {...});

your code should be:

<script type="text/javascript">

$(function() {
setInterval(function() {refreshBlock();},20000);
    $.ajaxSetup({ cache: false });     
});

 function refreshBlock()
    {    
       $('#block1').load("ChangedContent.cfm"); 
     }
</script>

Open in new window

0
 
RobOwner (Aidellio)Commented:
It will be a timing issue between the ajax and the setInterval call.  Can't be sure without seeing your full code.  Do you have the jquery dom ready call or do you just put that script at the bottom of your page?
0
 
jdthedjAuthor Commented:
Thanks for the reply Rob

The ready call and the code above are in the head of the document, then at the bottom of the page a query creates a list of page urls, then a session variable is set to zero.  This code follows

<DIV id="content_block" style="width:auto;height:auto;overflow:auto;">
<cfinclude template="ChangedContent.cfm">
</div>

At the top of the included page the session variable is increased by one, and the Url to include is read from the url list and the page the url points to is included in the ChangedContent page.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
RobOwner (Aidellio)Commented:
this code:

setInterval("refreshBlock()",20000);
    $.ajaxSetup({ cache: false }); 

Open in new window


needs to be in your ready call
e.g.
$(function() {
setInterval("refreshBlock()",20000);
    $.ajaxSetup({ cache: false }); 
});

Open in new window

0
 
jdthedjAuthor Commented:
Thanks Rob - but that doesn't work.  It stays on the first page forever
0
 
RobOwner (Aidellio)Commented:
ok, while i see it, I often use closure with setInterval, rather than passing a string for the function;

i.e.
change:
setInterval("refreshBlock()",20000);

to:
setInterval(function() { refreshBlock(); },20000);

This removes the use of eval() and removes the possibility that the function can be executed both in the setInterval and in its initialisation.

This should work within the $(function() { ... }); so given that it doesn't means there is something else amiss in the page or the order the scripts are loaded is playing a part but that's hard to know without seeing your page's full rendered html code or a link to the site.
0
 
jdthedjAuthor Commented:
OK Rob - I have uploaded to the website.  the url is

http://www.advancedpersonnel.co.nz/a/job_posting_Display.cfm

As mentioned, now only the first page displays continuously.
0
 
jdthedjAuthor Commented:
Thanks Rob - that's great - working now thanks.  I'll leave this open a while and leave the code running in case it starts skipping again, then I'll come back to you.
0
 
RobOwner (Aidellio)Commented:
Sounds good.  you should probably see something in the next 10 minutes or so right?
0
 
jdthedjAuthor Commented:
Yes, that would be correct
0
 
jdthedjAuthor Commented:
Looks like it has gone round the loop once and stopped
0
 
RobOwner (Aidellio)Commented:
yep.  at the end of the show, your cfm script must be sending a header to redirect to Job_Posting_Display.cfm
0
 
jdthedjAuthor Commented:
OK looks like it's all go!  Thanks very much for all your help
0
 
RobOwner (Aidellio)Commented:
No problem. :)  Thanks for the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.