Richard Trahan wrote:
I want a js function to call a Perl script residing on a server.
The Perl script will return a string, to be used by the js.
Pseudo code:
<script>
stringvar = perlfunc_on_server(stringarg)
document.write(stringvar)
</script>
Can stringvar above be a url?
The perlfunc_on_server could take the form of a GET,
like http://www.myserver.com/cgi-bin/perl...?arg=stringarg
Any other kludge is okay, as long as it works.
I'm very experienced with Perl, but a newbie to js.
Source code would help. Thanks.
Hi,
If you need JS to get some interaction with a SERVERSIDE script, you have
to:
1) call that script
2) receive the response and do something usefull with it.
the easiest way is to use a hidden frame (or a new window, as long as you
have a window) in which you replace the URL with your call to the
Perlscript.
The Perlscript has to respond in a way that can be used in javascript.
In such situations I always let the server respond with a normal HTML-page
that has an onLoad-handler that call some javascript-function.
That function contains serverside information you need.
Eg (php example because my Perl sucks)
<html>
<head>
<script type="text/javascript">
function passInfo(){
alert("I received: <?= $_GET["userid"] ?>");
}
</script>
</head>
<body onLoad="passInfo();">
Leave this empty, not needed.
</body>
</html>
if you call the above page in some hidden frame it will respond with an
alert saying 'I received: 23':
example.php?userid=23
The $_GET example is lame of course, but you can just do all your serverside
Perlstuff over there.
Instead of the alert you can call some JS-function in your main-page,
possibly passing the needed info from the server.
Stuff you need to know to do this is:
1) how you make (hidden) frames. (frame and frameset)
2) replace the content of a window
top.frames["framename"].location = .......
3) how to make calls to a JS-function in another window.
top.frames["someFrameName"].someFunction(1,2,3);
Hope that helps.
Good luck,
Erwin Moller