/    Sign up×
Community /Pin to ProfileBookmark

Connect a js var to cgi-bin output.

I would like to load a javascript variable with the output from a perl cgi-bin script. Something like this:
var myVar = getData(“../cgi-bin/myPerlScript.pl”);
At present, when I run a perl script, its output replaces the window contents. I would just like to get data from the perl script and then use it in my current page.
Thanks for any suggestions. (RL)

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@sciguyryanJan 10.2005 — Javascript can not interact with anything other than Other JS scripts and HTML and both of those are limited for security reasons, and for this reason I believe what you ask can not be done.


RyanJ
Copy linkTweet thisAlerts:
@rblauterauthorJan 10.2005 — Thanks Ryan. That's what I was suspecting.

However, I have used a page with 2 frames, where the bottom frame was loaded from a cgi-script. So from the top frame, I was thinking I could get the data from the other frame. But, I would rather not use frames, or at least make the bottom frame very small. Does this make sense? Thanks.
Copy linkTweet thisAlerts:
@CharlesJan 11.2005 — You do, however, have a few options. If you can edit the CGI script, simply have it return:

[font=monospace]Content-Type: text/javascript; charset=ISO-8859-1

myVar = 'foo'[/font]

And then call it with:

[font=monospace]<script src="../cgi-bin/myPerlScript.pl" type="text/javascript"></script>[/font]

If you can't monkey with the script but you do have access to SSI then know that you can include the output from scripts:

[font=monospace]var myVar = getData("<!--#include virtual="../cgi-bin/myPerlScript.pl" -->");[/font]

Though, you may find that the script still needs to prepend an HTTP header.
Copy linkTweet thisAlerts:
@rblauterauthorJan 11.2005 — Thanks Charles. I have access to the perl script but not sure about SSI. So I will try your first suggestion. That is a cool idea.
Copy linkTweet thisAlerts:
@rblauterauthorJan 17.2005 — Just a confirmation: The above method of using a content type of text/javascript works like a champ. Thanks.
Copy linkTweet thisAlerts:
@senshiJan 17.2005 — [i]Originally posted by sciguyryan [/i]

[B]Javascript can not interact with anything other than Other JS scripts and HTML and both of those are limited for security reasons, and for this reason I believe what you ask can not be done.





RyanJ [/B]
[/QUOTE]


DONT! forget that special javascript's VBarray where you can pass data from Javascript to VBscript via that Array....

as for using server-side to run client-side, exactly how does that work??
Copy linkTweet thisAlerts:
@CharlesJan 17.2005 — [i]Originally posted by senshi [/i]

[B][A]s for using server-side to run client-side, exactly how does that work?? [/B][/QUOTE]
By using a server side script to write JavaScript.
Copy linkTweet thisAlerts:
@senshiJan 17.2005 — [i]Originally posted by Charles [/i]

[B]By using a server side script to write JavaScript. [/B][/QUOTE]

I know it can write javascript.

You misunderstood my question and I also bring into question the issue of running perl on a surfers machine, how can you be sure that the user has perl installed on their machine? I have tried several examples thats given about running perl from the command line, I dont have it and as expected it created errors reporting that perl couldnt be found.

So how you pull off getting a server-side language to run client-side is still a bit of a feat and IM just wondering how you pulled it off.
Copy linkTweet thisAlerts:
@CharlesJan 17.2005 — Yes, I did misunderstand the question. You can't, as a rule, get a server side script running client side. When you do the script is called a "virus".
×

Success!

Help @rblauter spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...