I know this subject has been well discussed, but I haven't found
exactly what I'm looking for in the archives, or if it's possible.
I need to call a cgi (actually, mod_perl) script, but not on every page
hit - preferably just on the first. I'm dealing with a static site and
what I'd like to do is use javascript to read a cookie, and if the
cookie is found, I'll use the value from the cookie to display some
html.
However, if the cookie isn't found, then I need to call a perl script
that will do some processing, set a cookie, but somehow I need to get
the value back - the same value that is used to set the cookie -
without reloading the page. I know I can use javascript
src="/path/to/myscript" and have the Perl script write javascript
(setting my variable which I can use later), but then I couldn't use
the "if" logic to see if I actually need to call the Perl script as the
client side javascript will be overridden by the "src" attribute...
Example code...
--
// my sub, returns value for cookie name 'country'
var country = GetCookie('country');
if (country == null) {
alert('No cookie found - Call script/Set cookie');
var url = "/cgi-bin/geo.cgi";
// Here's what I need....
// country=output of cgi
// Perl script will set cookie with country,
// but I also need the value of country returned here,
// which the Perl script will output
} else {
alert('Cookie found ' + country);
}
document.write('<p>You live in, '+country);
--
Hope that makes sense....thanks.