Solved

Passing a JS var to PERL through SSI.

Posted on 1998-03-30
15
506 Views
Last Modified: 2013-11-18
Hi,
     I was wondering how I would go about sending a JS variable to a PERL script through SSI.  I've tried:

<!--#exec cgi="../cgi-bin/name.pl?parent.handle"-->
Where parent.handle = "bob"
but this doesn't work.

What it should do:
.
HTML would equal:
Bob's age is <!--#exec cgi='../cgi-bin/name.pl?parent.handle'-->
And the user would se:
Bob's age is 25.

How would I make it show the proper output so far I just get an error.
0
Comment
Question by:cide
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
  • +2
15 Comments
 
LVL 3

Expert Comment

by:percyn
ID: 1278948
I think you need to make JS print out the exec line so that the VALUE of the variable is passed to the CGI, not the variable itself.

e.g.

document.write ( "<!--#exec cgi='../cgi-bin/name.pl?" + myvar + " '-->

where myvar is the variable containing "Bob"
0
 

Author Comment

by:cide
ID: 1278949
No, that didn't work.  I did more experimenting with it and the problem seems to be when I add anything after the ? even normal text.
0
 
LVL 28

Expert Comment

by:sybe
ID: 1278950
try replacing the "?" with unescape(%nr) in which nr should be the ascii code for ?

so

document.write ( "<!--#exec cgi='../cgi-bin/name.pl" + unescape(%nr) + myvar + " '-->
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 10

Expert Comment

by:kollegov
ID: 1278951
Hmmm...
Probably in this case exec cgi=  do not set enviroment variables
And do not recognize ?query ...

you can try using cmd instead of cgi like:

document.writeln('<!--#exec cmd="some.pl '+yourvar+'"-->')

this will be equivalent to call from cammand prompt
>some.pl yourvarvalue

but in this case parameter will be passed trough
$ARGV[0] variable :)
and association of perl to .pl extension should be set in system.

0
 

Author Comment

by:cide
ID: 1278952
Doesn't solve the prob JavaScript is interprated after SSI.
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1278953
That what I'm was afraiding of....
Unfortunatly I do not find the way how to set enviroment
variables from Java Script. If this is possible you can pass
it through enviroment.
Last way is to pass through tmp file :(
Not the best solution...



0
 
LVL 2

Expert Comment

by:anguslai
ID: 1278954
Before anwsering this question, we have to take a look at when the SSI work and when the JavaScript Work.
1) Before the web server send html to browser, ir parse the html and execute all SSI command in the html.
2) Server send the page to web browser.
3) Web Browser execute client side script (javascript) and html.

           Web Server                                           Web Browser
   -------------------------------------------                    --------------------------------------------------------
 |  html  -> execute SSI          |   ----------->   | execute JS, HTML, client side element|
  -----------------------------------------                     ----------------------------------------------------------

Therefore, If you try to pass client side javascript to a SSI, it will 100% fail. (In SSI state,
the web server don't know what is javascript. (except server-side javascript with Netscape server or ASP with microsoft Information Server)
 
However, there is 1 way to pass JS variable to cgi program in a html page.
you can use :
<img src="http://aaa/cgi-bin/myCGI?name=jsVar">
(sure, you have to use document.write() to write out this line with your jsVar)
In this case, your cgi must return a image, not text.

If you can explan your project more detail, likely we can provide you better answer.
0
 

Author Comment

by:cide
ID: 1278955
Hi,
    What we are trying to do is setup a login script.  We have it now so a person enters their username and pword into a form and this data is passed to PERL script for verification.  If this data is correct it returns a frameset (which is our main page).  The frameset also stores their handle though, as a JS variable.  We can then access their name whenever we want through parent.handle.  However we are having trouble sending this variable to SSI.  We don't want the user to have to click a submit button in order to run every script and we would also like to generate only part of a page at a time like SSI does.....
0
 
LVL 3

Expert Comment

by:percyn
ID: 1278956
Then you are using SSI INCORRECTLY !!!!

If you want to call the perl script and pass it some arguments, try

location.href="/cgi-bin/myperlscript.pl?myvar"
 in Javascript.
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1278957
Well, Guys, BTW, what JS do you mean, when I answered this question I thought that you mean server-side JavaScript without any doubts, Anguslai in his answer supposed client-side script.
the whole scheme should be:

FILE->SSI(Perl)->ServerSsideJavaScript-->>--ClientJavaScript->HTML

So,Cide, just tell what side JavaScript you mean in question?

0
 

Author Comment

by:cide
ID: 1278958
Client Side I'm not sure if my server supports Server Side.
0
 

Author Comment

by:cide
ID: 1278959
I think Percyn almost has it except I don't want it to go to a new page.  I want it to append to the current page.  So use location.href="/cgi-bin/myperlscript.pl?myvar" but somehow get it not to go to a new page, just write in the current one.  Is this possible?
0
 
LVL 2

Accepted Solution

by:
anguslai earned 100 total points
ID: 1278960
I guess you working in wrong direction.

Your current process is :
1) user type in userID and password
2) a perl cgi verify the id and pass and return something similar to the following:
   <frameset rows="50%, *">
       <frame name="A" src="pageA">
       <frame name="B" src="pageB">
   </frameset>
   and you have already set parent.handle in either pageA or pageB.
3) In pageA or pageB, you want to use SSI to invoke another CGI to get data into the page.

NOTE: If  pageA is generate by a script (the script adding some javascript variable to the page), SSI does not run at all. SSI work only if the web server return a web page to browser directly.

** Passing SSI with javascript is WRONG DIRECTION in this project.
Honestly, you should :
A) insert <!--#exec cgi="../cgi-bin/name.pl?bob"-->  directly to the html page, then return the following to the browser.
    <frameset rows="50%, *">
       <frame name="A" src="pageA.html">
       <frame name="B" src="pageB.html">
   </frameset>

OR

B) return the following to the browser :
   <frameset rows="50%, *">
       <frame name="A" src="pageA.cgi">
       <frame name="B" src="pageB.html">
   </frameset>
   in the program pageA.cgi, you execute name.pl and insrt the result to the page, then print out pageA.html to the browser.

   I know the solution is not that easy to do (require you to modify some existing scripts). However, if you still try to play around with the SSI, I bet you never finish this project.I'm sorry to bring this bad news.

Good Luck to you.
0
 
LVL 2

Expert Comment

by:anguslai
ID: 1278961
By the way, why you post this question in perl section with 200 points, but post the same question in JavaScript Section with 100 Points?
Please reduce the point in Perl Section to 150 and increase point to 150 in JavaScript Section. (Unless you think that people who answering question in JavaScript section should earn less!)
0
 

Author Comment

by:cide
ID: 1278962
Sorry, can't decrease points in other question.  Although, this seems to be going nowhere fast.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses how to create an extensible mechanism for linked drop downs.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question