User Guide
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>