Returning Results to the User
57
When you flush data, make sure that a sufficient amount of information is available,
because some browsers might not respond if you flush only a very small amount.
Similarly, if you use an
interval
attribute, set it for a reasonable size, such as a few
hundred bytes or more but not many thousands of bytes.
Caution
After you use the
cfflush
tag on a page, any CFML function or tag on the page that
modifies the HTML header causes an error. These include the
cfcontent,
cfcookie,
cfform,
cfheader,
cfhtmlhead,
and
cflocation
tags. You also get an
error if you use the
cfset
tag to set a Cookie scope variable. All errors except Cookie
errors can be caught with a
cfcatch type="template"
tag. Cookie errors can be
caught with
cfcatch type="Any"
.
The following example uses the
cfloop
tag and the
rand()
random number
generating function to artificially delay the generation of data for display. It
simulates a situation in which it takes time to retrieve the first data and additional
information becomes available slowly.
<html>
<head>
<title>Your Magic numbers</title>
</head>
<body>
<H1>Your Magic numbers</H1>
<P>It will take us a little while to calculate your ten magic numbers.
It takes a lot of work to find numbers that truly fit your personality.
So relax for a minute or so while we do the hard work for you.</P>
<H2>We are sure you will agree it was worth the short wait!</H2>
<cfflush>
<cfflush interval=10>
<!--- Delay Loop to make is seem harder --->
<cfloop index="randomindex" from="1" to="200000" step="1">
<cfset random=rand()>
</cfloop>
<!--- Now slowly output 10 random numbers --->
<cfloop index="Myindex" from="1" to="10" step="1">
<cfloop index="randomindex" from="1" to="100000" step="1">
<cfset random=rand()>
</cfloop>
<cfoutput>
Magic number number #Myindex# is: #RandRange( 100000,
999999)#<br><br>
</cfoutput>
</cfloop>
</body>
</html>
Summary of Contents for COLDFUSION 5-DEVELOPING
Page 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Page 58: ...38 Chapter 3 Querying a Database ...
Page 134: ...114 Chapter 7 Updating Your Database ...
Page 210: ...190 Chapter 10 Reusing Code ...
Page 232: ...212 Chapter 11 Preventing and Handling Errors ...
Page 238: ...218 Chapter 12 Using the Application Framework ...
Page 262: ...242 Chapter 12 Using the Application Framework ...
Page 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Page 320: ...300 Chapter 15 Indexing and Searching Data ...
Page 336: ...316 Chapter 16 Sending and Receiving E mail ...
Page 374: ...354 Chapter 18 Interacting with Remote Servers ...