>> GreenByte.info By Nick Tong (quiksilv) | Supported by: TalkWebSolutions.co.uk

Banner rotation via Ajax

After viewing a great post from http://www.phpied.com/ajax-banner-rotation/ I've created the back end script in coldfusion. You'll have to download the JS from the post above, as I feel the post is worth a read. The backend code is:

<cfset request.banner = structNew() />
<cfset request.banner[1] = "<p>FREE Delivery</p>" />
<cfset request.banner[2] = "<img src='/images/banner1.gif'/>" />
<cfset request.banner[3] = "<p>Best offers on the net</p>" />
<cfset request.banner[4] = "<p>Visit <a href='http://succor.co.uk'>http://succor.co.uk</a></p>" />
<cfxml variable="request.XMLData"><?xml version="1.0" encoding="ISO-8859-1"?>
   <banner>
      <content><![CDATA[<cfoutput>#request.banner[randrange(1,4)]#</cfoutput>]]></content>
    <reload>11000</reload>
</banner>
</cfxml>
<cfsetting showdebugoutput="no" />
<cfcontent type="application/xml; charset=UTF-8" reset="yes"><cfoutput>#request.xmlData#</cfoutput>

Be sure to change the JS code on line 60 to ajax-banner.cfm then include this code on your page:

<script type="text/javascript" src="http://<cfoutput>#request.siteName#</cfoutput>/javascript/ajax-banner.js"></script>
div id="ajax-banner">Loading...</div>
The XML struct can contain images etc but no JS.

Enjoy.


 
Comments
Raymond Camden's Gravatar When you can - can you please make the CSS change described here:

http://www.coldfusionjedi.com/index.cfm/2007/7/26/...
# Posted By Raymond Camden | 28/07/07 13:35 | Report abusive comment
Nick Tong's Gravatar Done, can you let me know if it's worked Ray as i don't have a mac to hand, thanks.
# Posted By Nick Tong | 28/07/07 14:47 | Report abusive comment
Raymond Camden's Gravatar Excellent. Thanks!
# Posted By Raymond Camden | 28/07/07 15:21 | Report abusive comment
BlogCFC was created by Raymond Camden. This blog is running version 5.5.1.