CFTHREAD with a loading message

As yet another followup to my blog entry on CFTHREAD, a user asked about how to present a 'Please stand by' type message while the threads were running. This is fairly trivial with JavaScript and CFFLUSH: <cfset threadlist = ""> <cfloop index="x" from="1" to="5"> <cfset name = "find more cowbell #x#"> <cfset threadlist = listAppend(threadlist, name)> <cfthread name="#name#"> <cfset sleep(3000)> <cflog file="tdemo" text="All done with, baby."> </cfthread> </cfloop>

<cfoutput> <span id="loader"> #repeatString(" ",250)# Please stand by... </span> </cfoutput> <cfflush>

<cfthread action="join" name="#threadlist#" /> <script> document.getElementById('loader').innerHTML = '' </script>

<cfdump var="#cfthread#">

This is a slightly modified version of my previous code entry. Notice that I've added a span called loader with a bit of HTML. (The white space in front is to ensure IE renders the text.) After the cfthread/join action, I then use a bit more JavaScript to get rid of the loader. That's it. I'd normally use jQuery and some fancy loading graphic (like a unicorn, a magical unicorn), but hopefully you get the idea.

Like This?

If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can also subscribe to the email feed to get notified of new posts.