Geoff wrote on 03 Dec 2003:
<snipped my post>
Unfortunately, I don't know PHP, so I don't really understand
your expample. I tried using a Server Side Include, but that
failed.. Here's a snippet of code:
"<!--#exec cgi="/cgi-bin/callTrack.cgi action=view"-->"
The example didn't really require knowledge of PHP. The idea was to
show how to assign a server-side variable to a JS variable. I just
used PHP syntax, because that's the only syntax I know. You could
replace the PHP code with CGI equivalent for:
var jsVar = writeCGIVariable( $counter );
Where writeCGIVariable is a CGI function that takes a CGI variable
($counter) and outputs it to a text string with a trailing semicolon
so that when the browser gets it, it looks like:
var jsVar = <some number>;
That was all I was trying to show.
Note: The document.write example is pointless. If you can output
text, why output text for JS to then output again?
In my mind, this calls callTrack.cgi and passes the parameter
action=view. This doesn't work.
As far as the buttons go, I don't want the output of
callTrack.cgi?action=add to be printed to the screen, I just
want it to update the file that contains the current call count.
So, that's why I wanted to use javascript so I could do
something like:
execute callTrack.cgi action=add
reload this page.
I hope I'm making myself clear.
OK. In order to update the value on the server, it's obvious that you
need to make another HTTP request, during which time the count is
updated. There are two possible (related) ways:
1) Do what my buttons did: navigate to another page. The page can
have exactly the same contents as it did before, but during the
reload, the CGI script is invoked and the count is updated.
2) Hide something somewhere that gets reloaded (instead of the page)
and updates the counter.
The first option is quite a bad idea as the user has to re-request
the entire page, and gets nothing from it (no new content). The
second is a fudge, but is transparent to the user.
The hidden object can be anything, really. What would be ideal is if
your update script (callTrack) always returned a small transparent
GIF, rather than HTML. I don't know if you can do it, though. With
this approach, you would include an image, and update the source when
the buttons were clicked:
<IMG id="dummy" src="callTrack.cgi">
[Doesn't alter the script's values - just gets the transparent GIF]
<SCRIPT type="text/javascript">
function updateCount( action ) {
document.getElementById('dummy').src = 'callTrack.cgi?action='
+ action;
}
</SCRIPT>
<BUTTON type="button" onclick="updateCount('add')">Add</BUTTON>
As I said, you could theoretically update any object. For example, an
IFRAME (it would use the same script and BUTTON above):
<IFRAME id="dummy" src="callTrack.cgi" width="1" height="1"
style="display: none">
You wouldn't have to return binary data here. You could return
nothing at all.
To be honest, this is far from my area of expertise, so there may be
more elegant ways of doing it, but they would still boil down to
sending a HTTP request of some description.
My final note: if the user has JavaScript disabled, this won't work.
You could replace the buttons with regular links if that's a concern,
but then you'd be limited to only the first option I presented above
(a full page refresh).
Mike
--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)