Using jQuery load in place of a cfdiv

As many of you know, yesterday I ventured into the world of jQuery for the first time. I'm a little late to the party so I've decided that in order to get proficient with jQuery before the apocalypse I'm going to have to use it in my everyday client development tasks.

To give you some background, I have a long, on-going project where I'm creating a warehouse management/manufacturing application using ColdFusion 8 and SQL Server 2005. The app is huge and I've been using lots of out of the box cfajax widgets and cfajaxproxy to do cool things. I wanted to see how tough it would be to make jQuery do the same type of thing that I would normally use a cfdiv to accomplish. The quick answer? Easy, easy, easy - so easy that I couldn't believe it and had to ask Ray Camden if it were truly that easy or if I had made some sort of lucky mistake. I said, "Ray - it's too fast and too easy" and he said "Is that even AIR that you're breathing???" so here we go!

First off, I had a simple cfdiv that was bound to a URL...

view plain print about
1<cfdiv bind="url:quickprocessflow.cfm?jobTemplateCode=#jobTemplateCode#">

To give you an overall visual, we have a multi-tabbed form with master info, a grid that displays steps related to the job that we're looking at and then finally our friend the cfdiv (in yellow) that shows the entire series of steps for the job in a straightforward, linear fashion as illustrated below...

Replicating the functionality of the cfdiv turned out to be super easy. First, we need jQuery and we need to use load to essentially perform a GET on the quickprocessflow.cfm page which takes one URL parameter to tell it which Job Template Code to gather Job Template Steps, or process flow information.

view plain print about
1<script type="text/javascript" src="jquery/jquery-1.3.2.min.js"></script>
2
3<script>
4    $(document).ready(function(){
5        refreshProcessFlow();
6    });
7    
8    function refreshProcessFlow(){
9        $(document).ready(function(){
10            var jobTemplateCode = '<cfoutput>#URL.jobTemplateCode#</cfoutput>';        
11            $("#processFlow").load('quickprocessflow.cfm?jobTemplateCode=' + jobTemplateCode);
12        });    
13    }

My cfgrid has buttons above it for adding, editing and deleting process steps. So when the user adds a new process step I need to make certain that my div (formerly cfdiv) will refresh itself to reflect the changes that the user has made using the cfgrid. Because of this, when I close and kill (or destroy) the cfwindow that my users enter Job Steps into, I need to refresh my div to keep it current. Take a look below and you'll see that I'm doing just that in my other, cfwindow related, javascript functions. I'm actually using jQuery in my onHide handler function killJobTemplateDetailWin when I call refreshProcessFlow as shown below...

view plain print about
1killJobTemplateDetailWin = function(winToKill){
2        ColdFusion.Window.destroy(winToKill, true);
3        ColdFusion.Grid.refresh('gridJobTemplateDetail', true);
4        refreshProcessFlow();
5    }
6    
7    closeJobTemplateDetailWin = function() {
8        ColdFusion.Window.onHide(jobTemplateDetailWin, killJobTemplateDetailWin);
9        ColdFusion.Window.hide(jobTemplateDetailWin);
10    }

So to recap, jQuery is using load to GET quickprocessflow.cfm when the user initially browses to the page and ColdFusion is firing it up as well when the cfwindow is destroyed. Now I just simply have a plain old div named processFlow...

view plain print about
1<div id="processFlow"/>

Be sure to tune in next week to see jQuery shout "You Lie" really loudly when Kanye West disrupts any number of events.

Related Blog Entries

Comments
Chris Dawes's Gravatar Nice one...

You can also extend ExtJS with the jQuery Adapter so that you can talk back and forward between the two using the connector.

It's just as easy to do it directly in extjs also

[code]
Ext.onReady( function() {
Ext.get('processFlow').load('quickprocessflow.cfm?jobTemplateCode=#URL.jobTemplateCode#');
})
[/code]
# Posted By Chris Dawes | 9/17/09 9:55 PM
Aaron S.'s Gravatar Would this type of solution help solve the issue of CFDIV stripping <script> tags within the called ajax page?
I'm trying to use Spry widgets within a CFDIV and it doesn't work because it can't include the .js files.
# Posted By Aaron S. | 10/30/09 4:35 PM
Andy Sandefer's Gravatar @Aaron
This might work better for you then cfdiv. I've learned the hard way that you can't really mix spry and cf8's ajax stuff with any real success.
# Posted By Andy Sandefer | 10/30/09 5:23 PM
Lana's Gravatar thanks for the code, been looking everywhere for this. http://www.rapidsloth.com has some code but wasnt complete.
# Posted By Lana | 3/9/10 3:44 AM
# Posted By Sarah | 4/15/10 7:25 AM
remik's Gravatar In my opinion, material of this article is very useful. http://findrapidlinks.com/210410/mapa1.html
# Posted By remik | 4/21/10 6:45 PM
mbt shoes's Gravatar Aww, this was a really quality post. In theory I’d like to write like this too – taking time and real effort to make a good article… but what can I say… I procrastinate alot and never seem to get something done.
# Posted By mbt shoes | 5/17/10 3:21 AM
# Posted By coach handbags | 5/30/10 11:20 PM
# Posted By ed hardy clothing | 6/7/10 12:20 AM
ed hardy clothing's Gravatar http://www.4unj.com/ wholesale nfl jerseys
http://www.4unj.com/ cheap nfl jerseys
http://www.4unj.com/ Youth nfl jerseys
# Posted By ed hardy clothing | 6/9/10 5:00 AM
coach bags outlet's Gravatar I really like your article, I support your point of view
# Posted By coach bags outlet | 6/18/10 4:18 AM
new era mlb hats's Gravatar So beautiful sharing!Thank you very much.
Best wishes!Your article is very good!
It is so nice. <a href="http://www.goahats.com/new-era-mlb-hats-c-18.html">new era mlb hats</a>
Welcome to visit our website:
http://www.goahats.com/new-era-mlb-hats-c-18.html
# Posted By new era mlb hats | 6/18/10 11:40 AM
new era baseball hats's Gravatar We wholesale hats at competitive price,providing a huge range of hats with different brand name,such as coogi hats, polo hats,Jordan hats,famous hats,dc shoes hats,new era MLB hats, etc.You can buy cheap hats. Welcome to visist here. <a href="http://www.goahats.com/new-era-mlb-hats-c-18.html">new era baseball hats</a>
?http://www.goahats.com/new-era-mlb-hats-c-18.html
# Posted By new era baseball hats | 6/22/10 12:20 AM
<a href="http://www.sportsjerseysshop.com&'s Gravatar Thanks for posting this. <a href="http://www.sportsjerseysshop.com">cheap nfl jerseys</a>
<a href="http://www.sportsjerseysshop.com">wholesal... nfl jerseys</a>
<a href="http://www.sportsjerseysshop.com">discount... nfl jerseys</a>
Very nice recap of some of the key points in my talk. I hope you and your readers find it useful! Thanks again
# Posted By <a href="http://www.sportsjerseysshop.com& | 6/28/10 10:08 AM
all star shoes's Gravatar It's quite interesting.I will look around for more such post.Thanks for sharing..
http://www.ed-hardy-outlet.net/ ED Hardy Outlet
http://www.ed-hardy-outlet.net/ ED hardy clothing
# Posted By all star shoes | 7/13/10 11:44 AM
cap hat shop's Gravatar thanks for your sharing !!!!! welcom to http://www.caphatshop.com .
<a href=" http://www.caphatshop.com"" target="_blank">http://www.caphatshop.com"; title="New Era Hats For Wholesale">New Era Hats For Wholesale</a>
<a href=" http://www.caphatshop.com"" target="_blank">http://www.caphatshop.com"; title="New Era Caps For Wholesale">New Era Caps For Wholesale</a>
<a href=" http://www.caphatshop.com"" target="_blank">http://www.caphatshop.com"; title="Monster Energy Hats For Wholesale">Monster Energy Hats For Wholesale</a>
<a href=" http://www.caphatshop.com"" target="_blank">http://www.caphatshop.com"; title="Red Bull Hats For Wholesale">Red Bull Hats For Wholesale</a>
# Posted By cap hat shop | 7/17/10 12:24 AM
Wholesale NFL Jerseys's Gravatar <a href=”http://www.4unfl.com”>Cheap NFL Jerseys</a>
<a href=”http://www.4unfl.com”>Wholesale NFL Jerseys</a>
<a href=”http://www.4unfl.com”>Discount NFL Jerseys</a>
<a href=”http://www.4unfl.com”>Cheap NFL Jerseys from china</a>
# Posted By Wholesale NFL Jerseys | 7/19/10 10:59 PM
Gucci outlet's Gravatar wow,so many people leaving comment on your post,they express their opinion.I think it's very good
for sharing our opinions together,as the saying goes:honesty is the best policy.no matter the difference
view we have,everyone has the rights to express freely,am i right?
http://www.cheap-shoesonline.com/ cheap shoes online cheap ed hardy
# Posted By Gucci outlet | 7/24/10 11:04 AM
cheap nfl jerseys's Gravatar Hey guys,
I hope this allowed, I have never used this website before so I wasn't really sure what this was going to do. <a href="http://www.nfljerseyse.com"; title="wholesale nfl jerseys">wholesale nfl jerseys</a> So this is just a test post. I really like this forum, it has some excellent discussions that take place.
# Posted By cheap nfl jerseys | 7/26/10 11:47 PM
mbt shoes's Gravatar thanks for your information .
# Posted By mbt shoes | 7/29/10 5:36 AM
ciphone's Gravatar Hello!everyone!iphone is so expensive.so I like <a href=" www.efox-shop.com/index.php/cPath/5_35
" rel="nofollow"> Ciphone </a>. d^_^bIt is very interesting.I want to introduce <a href="http://www.efox-shop.com/"; rel="nofollow"> efox-shop</a> to you.
# Posted By ciphone | 7/30/10 11:18 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.5.007. Contact Blog Owner