Tuesday, March 30, 2010

CFFLUSH and CFLOCATION don't work...

I got a codes example from http://tutorial209.easycfm.com/ which is perfect for what I need. This little code is using cfflush to display ''please wait'' message.

It worked perfectly when I applied this code to my action page BUT unfortunately after the action page is done processing, normally a cflocation is ran at the end of action page to show the report page.

When I did not include this cfflush and the script, after finish processing my action page the cflocation called the report page but when I include cfflush and the script on my action page, cflocation is prevented from being called, so the process stop at the action page and I don't get to see my report page.

Does cfflush for some reason preventing cflocation from running???

Here is my code:

%26lt;!--- I put cfflush code on TOP of my action.cfm page---%26gt;

?%26lt;cfflush interval=''1''%26gt;
?%26lt;!--- show the message saying there will be a delay ---%26gt;
?%26lt;p id=''wait'' style=''color:red; background-color: #CCCCCC; width: 200px; height: 50px;''%26gt;Please wait while the data is processing.%26lt;/p%26gt;

?.

?%26lt;cfinclude is working in here%26gt;

?.

?%26lt;cfif%26gt;

%26lt;!--- some codes here ----%26gt;?

?%26lt;cfif%26gt;

?%26lt;!--- some more codes and queries here ----%26gt;

?%26lt;cfif%26gt;

%26lt;!--- some more codes and some more queries here ----%26gt;

%26lt;/cfif%26gt;

?%26lt;!--- This script goes with CFFLUSH ---%26gt;

?%26lt;script%26gt;

if (document.getElementById) {

?wait

.style.display=''none'';}

%26lt;/script%26gt;

%26lt;/cfif%26gt;

%26lt;/cfif%26gt;

%26lt;!--- This cflocation is not run once the process is done BUT it is ran when I took out the cfflush and script ---%26gt;

%26lt;cflocation url=''showreport.cfm?y=#lyear#%26amp;fn=#reportname#''%26gt;

Does anyone know why my cflocation doesn't get call when I include cfflush and the script????

CFFLUSH and CFLOCATION don't work...

Yes %26lt;cflocation...%26gt; is one of the tags that does not work with a %26lt;cfflush...%26gt;

%26lt;cfflush...%26gt; starts sending a response to the client piece by piece.

%26lt;cflocation...%26gt; works by sending a 302 redirect header to the client.

Once the client has started processing the parts sent by the flush it is too late for the client to respond to a header.

You would have to do this with a %26lt;meta ....%26gt; refresh if you would like similar functionality.

CFFLUSH and CFLOCATION don't work...

There are two more alternatives. First, if you know how long it takes the page to load, then you can redirect using Javascript, as follows

%26lt;html%26gt;
%26lt;head%26gt;
%26lt;script type=''text/javascript''%26gt;
/* redirect client in 5000 millisecs, that is, in 5 seconds */
setTimeout('redirectClient()', 5000);
function redirectClient() {
?%26lt;cfoutput%26gt;window.location=''http://your_site/showreport.cfm?y=#lyear#%26amp;fn=#reportname#'';%26lt;/cfoutput%26gt;
}
%26lt;/script%26gt;
%26lt;/head%26gt;
%26lt;body%26gt;
%26lt;/body%26gt;
%26lt;/html%26gt;

Secondly, you may actually load the next page into the current one, as follows:

%26lt;cfhttp method=''get'' url=''http://your_site/showreport.cfm?y=#lyear#%26amp;fn=#reportname#''%26gt;
%26lt;!--- include content of next page ---%26gt;
%26lt;cfoutput%26gt;#cfhttp.filecontent#%26lt;/cfoutput%26gt;

BKBK wrote:

There are two more alternatives. First, if you know how long it takes the page to load, then you can redirect using Javascript, as follows

%26lt;html%26gt;
%26lt;head%26gt;
%26lt;script type=''text/javascript''%26gt;
/* redirect client in 5000 millisecs, that is, in 5 seconds */
setTimeout('redirectClient()', 5000);
function redirectClient() {
?%26lt;cfoutput%26gt;window.location=''http://your_site/showreport.cfm?y=#lyear#%26amp;fn=#reportname#'';%26lt;/cfoutput%26gt;
}
%26lt;/script%26gt;
%26lt;/head%26gt;


You could do this without the timing issue.?Just put the window.location script into the body of the HTML page after the processing is done.?While usually ideal, JavaScript does not have to be in head section.

I tested again your suggestion by putting the script below at the end of my code:

%26lt;script%26gt;

%26lt;cfoutput%26gt;window.location=''http://your_site/showreport.cfm?y=#lyear#%26amp;fn=#reportname#'';%26lt;/cfoutput%26gt;

%26lt;/script%26gt;

Compared to the META refresh tag this script gives a much better timing between the message being displayed to users, the message disappear after code processing is done and the end result which is the report.

very cool!!! Thanks guys!!

I wished my ''please wait...'' message could also change to different messages while the process is still running, such as, please wait....calculating optimum settings....initializing report engine....determining build parameters.....accessing records....building report...

But I guess I'm asking too much from you guys.

IF YOU REALY WANTED TO.

You could deliver javascript content that changes the text of an element as you process the page.

%26lt;p id=''message''%26gt;Starting the process%26lt;/p%26gt;

...

%26lt;script%26gt;document.getElementById(''message'').innerHTML = ''Processing'';%26lt;/script%26gt;

....

%26lt;script%26gt;document.getElementById(''message'').innerHTML = ''Calculating'';%26lt;/script%26gt;

....

%26lt;script%26gt;document.getElementById(''message'').innerHTML = ''All most done'';%26lt;/script%26gt;

....

%26lt;script%26gt;document.getElementById(''message'').innerHTML = ''I said we're almost there, do you want me to pull this program over, I will you know.'';%26lt;/script%26gt;

But I don't know if I would bother.

No comments:

Post a Comment