Posted in ColdFusion | Posted on 10-03-2008 | 7,693 views
A user on my forums asked about creating a region on his web page that would auto reload, like what he saw on att.com. I used to have an auto-reloading item on coldfusionbloggers.org, and I thought I had blogged on it, but wasn't able to find it. Forgive the dupe if you remember an earlier entry about this. Anyway, here is a real simple example.
First, I'm to start with a page that uses cfdiv to load the content I want to reload.
2
3<head>
4</head>
5
6<body>
7<h2>Where is Oktoberfest?</h2>
8
9<p>
10Foo
11</p>
12
13<cfdiv id="ad" bind="url:ad.cfm" />
14
15</body>
16</html>
The file I'm using, ad.cfm, will rotate between 4 ads, or pieces of content, or whatever. In my case it is a simple counter:
2<cfset maxAds = 4>
3<cfset session.counter++>
4<cfif session.counter gt maxAds>
5 <cfset session.counter = 1>
6</cfif>
7
8<cfoutput>
9<p>
10<b>This is ad #session.counter#</b>
11</p>
12</cfoutput>
So to start reloading the content, I'm going to set up a interval. I'll launch this using ajaxOnLoad:
and here is setup:
2 setInterval(reload,5000);
3}
This says, run the reload function ever 5 seconds. The reload function is pretty trivial:
2 ColdFusion.navigate('ad.cfm','ad');
3}
So all in all a very simple piece of code. I've included the entire template below.
2
3<head>
4<script>
5function reload() {
6 ColdFusion.navigate('ad.cfm','ad');
7}
8
9function setup() {
10 setInterval(reload,5000);
11}
12</script>
13</head>
14
15<body>
16<h2>Where is Oktoberfest?</h2>
17
18<p>
19Foo
20</p>
21
22<cfdiv id="ad" bind="url:ad.cfm" />
23
24</body>
25</html>
26<cfset ajaxOnLoad('setup')>


$(document).ready(function(){setInterval(function(){$('#ad').load('ad.cfm')}, 1000);});
Just providing alternatives. :)
Adam let me not agree with you about "brightcove.tv" it still under ColdFusion, just under TV domain they are using JSP, under COM they are using regular CFM (http://www.brightcove.com/index.cfm)
Plus it really not important what program languages they are using, its a business the goal is.....
your comment about Spry being the CF of js frameworks and then the follow up that it is friendly but not necessarily powerful (compared to jQuery) kind of implies that CF is also friendly but not powerful.
Do I think Spry is as powerful as jQuery? No. Does that mean I'd never use Spry - heck no. Right now I'm learning jQuery still and I'll have to figure out the best time to use one over the other.
My cfdiv is passing variables through the URL and I'm trying to use your example to actually update a cfchart (contained in another page - i'm using the url bind on the cfdiv). When I call a function via proxy and then try to reload the cfdiv the URL vars don't exist anymore. I'm probably pretty close to solving this but if you know off the top of your head it would help me meet an deadline.
Thanks
[Add Comment] [Subscribe to Comments]