On 2 January 2011 13:51, Chris G cl@isbd.net wrote:
On Sat, Jan 01, 2011 at 07:14:19PM +0000, Chris G wrote:
I want to implement a link to a CGI script that, when you click on it, does nothing to the currently displayed page. I.e. I want the existing page to continue to be displayed when I click on the link (and as a result of course the CGI script executes).
Actually even more perfect *might* be to force a redisplay of the current page as the CGI script will (hopefully) modify the page.
This sounds as if it must be something one often wants to do but being naive as regards HTML/CGI I don't know how to do it.
Well the answer is (or at least the simple one I have found) is to use the "Location:" HTTP header field.
All that's needed is for the (bash) CGI script to do:-
echo "Location: "<Absolute URI for page>
and when the CGI script exits (if the above is at the end) then the page specified gets displayed. Apparently even though the specification is that it should be an absolute URI a relative one works in most browsers.
All I want to do now is wind up the server timeout so that it doesn't matter how long the CGI script takes (it's me editing things).
If you're happy to use Javascript, then another way would be to post update messages to the client, which both prevents the technical timeout, and also gives confidence to the user that things are still happening. Something like ...
(right at the beginning, generate a blank page with a placeholder) echo <html><body><span id="updateSpan"></span></body>
(in processing loop, update the placeholder at regular intervals) echo <script type="text/javascript">document.getElementById("updateSpan").innerHTML = "Processed " + linecount + " lines";</script>
(and when processing has completed) echo <script type="text/javascript">window.location="http://example.com";</script>
Note that you'll need to ensure that your script isn't buffering the output; in Perl that would be done with $| = 1;
I've also been a bit lazy with my quoting, but hopefully you get the idea,
Greg