473,609 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling Perl script from javascript

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_ser ver(stringarg)
document.write( stringvar)
</script>

Can stringvar above be a url?

The perlfunc_on_ser ver 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.

Jul 23 '05 #1
6 15884
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_ser ver(stringarg)
document.write( stringvar)
</script>

Can stringvar above be a url?

The perlfunc_on_ser ver 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="passInf o();">
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?use rid=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["someFrameN ame"].someFunction(1 ,2,3);

Hope that helps.
Good luck,
Erwin Moller
Jul 23 '05 #2


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_ser ver(stringarg)
document.write( stringvar)
</script>
Well if you want to receive some text from the Perl script and display
it directly (document.write does that) I am not sure why you need
JavaScript at all, you could solve that on the server and use Perl to
read the text from the (other?) server and then include that in your
page with Perl.

Can stringvar above be a url?
What you can do with HTML is
<script type="text/javascript"
src="www.myserv er.com/cgi-bin/perlfunc_on_ser ver.pl?arg=stri ngarg"></script>
that way you simply need to make sure your perlfunc_on_ser ver.pl sets
the Content-Type to application/x-javascript and sends syntactically
correct JavaScript back.
The perlfunc_on_ser ver 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.


The biggest problem could be the same origin policy governing
client-side scripting so while in theory in new browsers like Mozilla,
IE5+/Win, Safari you can make HTTP requests and receive the result you
can usually only connect back to the server the HTML page with the
script comes from.
See
http://www.faqts.com/knowledge_base/.../17226/fid/616
http://jibbering.com/2002/4/httprequest.html

There are also solutions using an iframe (usually a hidden one) to
perform the request to the server and returning some script that updates
the document containing the iframe but in this case too you are
restricted by the same origin policy.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #3
Thank you for your detailed reply.

Although a great idea, I cannot create an invisible frame
because the client window is an eBay ad. eBay software will
detect the frame creation code and delete the ad, as they
explicitly prohibit frames.

Is it true in general that js functions which take a string
argument will also take a url? I.e., can I do something like
alert(url(http://myserver.com)) ?

Jul 23 '05 #4
Richard Trahan wrote:
Is it true in general that js functions which take a string
argument will also take a url? I.e., can I do something like
alert(url(http://myserver.com)) ?


This is partly true. Because an URL is also a string. You could call the
function:

alert("http://myserver.com")
Jul 23 '05 #5
Martin Honnen wrote:

Thank you for responding.
What you can do with HTML is
<script type="text/javascript"
src="www.myserv er.com/cgi-bin/perlfunc_on_ser ver.pl?arg=stri ngarg"></script>

that way you simply need to make sure your perlfunc_on_ser ver.pl sets
the Content-Type to application/x-javascript and sends syntactically
correct JavaScript back.


That's exactly what I'm looking for. Thank you so much. I have not
been able to find a decent textbook or tutorial that explains exactly
how the various MIMEs are used in CGI programming.
The texts on network programming are all obsessed with
sockets, not CGI. Do you know of a good book?
Jul 23 '05 #6
In article <cf**********@n gspool-d02.news.aol.co m>,
"Andre Herbst" <mo*******@comp userve.de> wrote:
alert("http://myserver.com")


Of course, it is going to display a message box with:

http://myserver.com

Probably not what the OP wants, but not sure what the OP is hinting at.

Robert
Jul 23 '05 #7

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

Similar topics

2
4741
by: Shailan | last post by:
Hi Im having trouble with the following code that seems to be behave differently when called from the browser as opposed to the command line. The calling script is a cgi that forks, with the child trying to call another cgi script and pass arguments to it. It works fine from the command line, and calls the required script and passes the arguments correctly. However, when it is run on the browser, it calls the script but does not pass...
1
1732
by: Richard Trahan | last post by:
I am using the following method to call a Perl script from js: <script type="text/javascript" src="http://myserver.com/cgi-bin/x.pl?x=abc" </script> The Perl writes an application/x-javascript header followed by some js code (like document.write). This works fine (thank you, Martin Honnen). I can't use the hidden frame method suggested by Erwin Moller because the client page is an eBay ad, and they will not allow any frame code.
3
2456
by: phal | last post by:
Hi all; I code Perl for CGI, I using regular expression to check the validation of user input, because the form is small and it run only from my own computer, anyways if many people using my form, do you think it will be slow due to Perl is run under server. How about using JavaSCript to check validation for user input? Do you think it a bit faster?
10
2455
by: Tony Rice | last post by:
If I've loaded a set of functions in a webdocument like this: <script language="JavaScript" type="text/javascript" src="/js/foo.js"</script> Shouldn't I be able to call a function from inside foo.js later in that same document by doing something like this: <script language="JavaScript" type="text/javascript">myfunction(myargs)
1
2607
by: stahl.karl | last post by:
Howdy, I have a CGI/Perl script that simply creates a few Javascript variables. For example: --------myCGI.pl---------------------------------------- print("Content-type: text/javascript\n\n")); print("var x = 5");
3
2156
by: Nathan Gilbert | last post by:
I am wanting to use javascript to select between different *.css files dependent on the user's browser. I am also wanting to generate the html document containing this javascript dynamically using PERL. So far, I have the javascript that does what I want to do, and it works fine as long as the the page was not generated by PERL. My problem is that when the javascript/html is generated by my PERL scripts the javascript never gets...
0
1602
by: nghivo | last post by:
I have a Struts application developed following the MVC method (forms, actions, beans, etc).. I have a JSP page with 2 buttons A and B. When B is clicked, a Struts action will be executed. But when A is clicked, I want to execute a script (ksh or Perl) on the server and get the response back to my form thru the use of (Javascript AJAX) Http Request object (hence, w/o refreshing my JSP page). So far so good except that instead of...
22
3432
by: Archanak | last post by:
Hi, I am using 2-level CSS Drop Down Menu in my perl/CGI program. here is the code. #!c:/perl/bin/perl.exe use CGI qw(:standard);
3
3899
by: happyse27 | last post by:
Hi All, I am creating the perl script using html form(with embedded javascript inside). When using this html form with javascript alone, it works where the form validation will pop up javascript windows to say the field is not keyed into properly. However, when i convert this html(with javascript inside) into perl script, the perl script did not validate when i keyed incorrect data in the form and it straight away executed perl script...
0
8139
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8091
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8555
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8232
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
6064
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4032
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.