473,581 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript/cgi

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('coun try');

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 .

Dec 15 '05 #1
7 1685
Can't you test for the cookie using perl at the top of the page? Ya
know, like (I don't know Perl, but this is PHP [close]):

<?php
$country = $_COOKIE["country"];

if (!isset($countr y) || empty($country) ) {
//Your server code ($errormsg = ..., or whatever)
}
?>

I not clear on what you're trying to accomplish, though.

Dec 15 '05 #2
spariam wrote:
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.


This sounds like a job for "just mod_perl".

Have a content handler that checks for the presence of the cookie and
declines to handle the request if its found, otherwise it sets the cookie
and redirects (to somewhere which doesn't demand the cookie - you don't
want to get people with cookies disabled stuck in an infinate loop!).

Another (possibly better) option, that doesn't need JavaScript or Cookies
would be to have the handler check for the cookie, if it finds it, it
declines to handle the request, and the server retrieves the page as
normal. If the cookie isn't there, then it sets the cookie, looks at the
requested URL, opens that file, looks in it for a specially formatted HTML
comment (you could borrow SSI syntax), and replaces it with the text you
want.

--
David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Dec 15 '05 #3
This issue is that the site is static...there' s no mod_perl, no php, no
SSI on the server where the html files reside. That's why I'd like to
use javascript...ho wever, I do need some dynamic action, which is why
I'd like to call an external mod_perl script. If we ran SSI, I'm pretty
sure a simple "exec" call would work, but as it stands, the mod_perl
script will have to reside on a different machine.

What I'm trying to accomplish is this...we need to display special html
for IPs that map to the US (using Geo::IP on the box that is running
mod_perl). So to limit the load to the mod_perl box, I'd like to use a
cookie check with javascript to see if the user has already visited
once and (hopefully) had a cookie set that contains the country code.
If no cookie is found (via javascript), then we make the remote call to
the external mod_perl script to set the cookie and somehow return the
country code back to the javascript. Actually, if I could get the
country code back in the javascript, I could set the cookie with
javascript too (assuming the client has javascript turned on, of
course).

So think of the call to the mod_perl script get the country call as a
"service" that any static page can call...

Dec 16 '05 #4

spariam wrote:
This issue is that the site is static...there' s no mod_perl, no php, no
SSI on the server where the html files reside. That's why I'd like to
use javascript...ho wever, I do need some dynamic action, which is why
I'd like to call an external mod_perl script.
[snip]
If no cookie is found (via javascript), then we make the remote call to
the external mod_perl script to set the cookie and somehow return the
country code back to the javascript. Actually, if I could get the
country code back in the javascript, I could set the cookie with
javascript too (assuming the client has javascript turned on, of
course).

So think of the call to the mod_perl script get the country call as a
"service" that any static page can call...


Oh, ok - I see what you're trying to do. Well, this sounds exactly
like a job for so-called AJAX (using the XMLHttpRequest object). This
would accomplish everything you're wanting to do - are you familiar
with this?

Dec 16 '05 #5
Joel Byrd wrote:
Oh, ok - I see what you're trying to do. Well, this sounds exactly
like a job for so-called AJAX (using the XMLHttpRequest object). This
would accomplish everything you're wanting to do - are you familiar
with this?


Yes, I'm familiar with AJAX, but I've never really looked at it
closely. Guess that'll be on tomorrow's schedule...

Dec 16 '05 #6
Just tried it...Ajax does exactly what I want.

Dec 16 '05 #7
Great!

Dec 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
7876
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7804
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7910
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6563
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.