Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML Forms/Not refreshing results page 1

Status
Not open for further replies.

MorganGreylock

Programmer
Jan 30, 2001
223
US
I have a couple CFM pages, one action page and one result pages. The problem is that when I change any data (combo boxes, text boxes, etc) on the first page, then click on the submit button again, I have to hit reload on the results page in order to see the changed data. I'm just using standard CFQUERY/CFOUTPUT tags, etc etc.

Does anyone have a clue why this is happening? I don't want my users to have to hit reload every time. I'm using Netscape 4.7 or so, and I have the 'Compare files to server' set to 'Never', so technically it shouldn't ever use the cache, although I know it does anyway.

Should I just reload the page automattically using a meta refresh in the results page, or is there a 'real' solution?

Thanks
MG
 
Here's a few suggestions:

This method id a bit hefty, but it's the technically correct method, and one of the few that AOL's proxies will pay attention to:

<CFSET gmt = gettimezoneinfo()>
<CFSET gmt = gmt.utcHourOffset>
<CFIF gmt EQ 0>
<CFSET gmt = &quot;&quot;>
<CFELSEIF gmt GT 0>
<CFSET gmt = &quot;+&quot; & gmt >
</CFIF>
<CFHEADER NAME=&quot;Pragma&quot; VALUE=&quot;no-cache&quot;>
<CFHEADER NAME=&quot;Cache-Control&quot; VALUE=&quot;no-cache, must-revalidate&quot;>
<CFHEADER NAME=&quot;Last-Modified&quot; VALUE=&quot;#DateFormat(now(), 'ddd, dd mmm yyyy')# #TimeFormat(now(), 'HH:mm:ss')# GMT#gmt#&quot;>
<CFHEADER NAME=&quot;Expires&quot; VALUE=&quot;Mon, 26 Jul 1997 05:00:00 GMT&quot;>

Alternatively, in the flow of an application, you often need to return the user to a page that has already been displayed--but you've already passed new variables to the page so it will dynamically output something different this time. Since you don't want the user looking at the old page, you need to ensure that the page refreshes somehow and makes a call to the server again for reprocessing.

Most popular browsers (Internet Explorer and Netscape) cache pages already visited on the local machine. Then, when another call is made for it, the browser pulls up the local copy rather than make another call for the page. This can prove to be a problem under the circumstances described above, since the old page will be displayed to the user.

The key to creating a workaround for this situation is to know that browsers identify a page by its URL--if the URL is the same as the one it just cached locally, it uses the local copy. Accordingly, you can simply append a dynamically created variable name to the URL, thereby producing a new URL and forcing the browser to make a subsequent call to the server to retrieve the new, and up-to-date, page. Here is an example of the code you can use to do this:

<CFLOCATION URL=&quot;index.cfm?norefresh=#Rand()#&quot;>
Rand() returns a random number in the range of 0 to 1, including fractions, so the URL will be different each time you call it, which forces the browser to request the page again from the server. That, in turn, ensures the most current information will be displayed.

A third option is to use standard META tags
<META HTTP-EQUIV=&quot;Refresh&quot; CONTENT=&quot;0;URL=MyPage.cfm&quot;>

But, META tags are for people who have only static pages, and cannot create HTTP headers. That's why it's &quot;HTTP-EQUIV&quot;. It tells the browser &quot;Pretend that you got this HTTP header&quot;.

But we have ColdFusion. ColdFusion creates HTTP headers very nicely, using the CFHEADER tag. If you want to create an HTTP header, then do it, rather than relying on the browser handling the META tag properly.

Try this in the HEAD of a document:

<CFHEADER NAME=&quot;Expires&quot; VALUE=&quot;Mon, 06 Jan 1990 00:00:01 GMT&quot;>
<CFHEADER NAME=&quot;Pragma&quot; VALUE=&quot;no-cache&quot;>
<CFHEADER NAME=&quot;cache-control&quot; VALUE=&quot;no-cache&quot;>

<!-- meta anti cache-->
[COLOR=000080]<META HTTP-EQUIV=&quot;Expires&quot; CONTENT=&quot;Mon, 06 Jan 1990 00:00:01 GMT&quot;>[/color]
[COLOR=000080]<META HTTP-EQUIV=&quot;Pragma&quot; CONTENT=&quot;no-cache&quot;>[/color]
[COLOR=000080]<META HTTP-EQUIV=&quot;Cache-Control&quot; CONTENT=&quot;no-cache&quot;>[/color]

- tleish
 
Well put! Bookmarking this page and &quot;voting&quot; this post helpful!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top