Running Perl Script from within javascript

V

von

Is it possible to run a Perl script from within a javascript?

I have an existing javascript that provides some data - and I want to write
that data to a text file on my server via a Perl script (that I also already
have).

Both scripts work great - I just don't know how to make them work together.

Is this even possible?

Thanks in advance for all input.

:)
 
C

Colin McKinnon

von spilled the following:
Is it possible to run a Perl script from within a javascript?

I have an existing javascript that provides some data - and I want to
write that data to a text file on my server via a Perl script (that I also
already have).

Both scripts work great - I just don't know how to make them work
together.

Is this even possible?

Thanks in advance for all input.

:)

Sort of....you can open a window or an iframe from javascript, and you can
post a form. So you can send parmeters serverside in a GET or load a form
from the server, populate it then POST it. The latter solution, although
more laborious, saves a lot of messing around with URL encoding.

HTH

C.
 
V

von

Thanks for your input Colin.

What I really want to accomplish is to take, say ...

===================
'Function Data1 ()'
{
[script here];

}
===================

and then send the results of 'Data1' to a text file on my server - all
without any windows popping up and without requiring any user input.

:)


"Colin McKinnon"
 
M

Mighty Krell

von said:
Thanks for your input Colin.

What I really want to accomplish is to take, say ...

===================
'Function Data1 ()'
{
[script here];

}
===================

and then send the results of 'Data1' to a text file on my server - all
without any windows popping up and without requiring any user input.

:)


XMLHTTPRequest
 
T

Tim Williams

How much data? If a small amount then

var i=new Image();
i.src="pathtoyourscript.pl?data=" + yourdata;

will work fine. But the HTTPRequest path is more robust....

Tim.
 
T

Tim Williams

This is a bit rough but will allow you to send moderate amounts of
data and get back a status response.

Tim


<HTML>
<HEAD>
<TITLE>Cookie Remote Scripting</TITLE>

<SCRIPT type="text/javascript">

var ErrorTimeoutSec=1.5;
var CookieName="cTest";
var tOut=null;
var NoResponse="No response";
var sImage=null;

function doIt(sMsg){
delCookie(CookieName);
var sURL="getInfo.asp?v="+escape(sMsg)+"&x="+escape(new Date());
sImage=new Image();
sImage.onload=function(){showMsg(true)};
tOut=window.setTimeout("showMsg(false)", ErrorTimeoutSec*1000);
sImage.src=sURL;
}

function delCookie(key){
var d = new Date();
d.setDate(d.getDate() - 2);
document.cookie = key+'=deleted; expires='+d.toGMTString()+';';
}


function showMsg(bOK){
sImage=null;
if(tOut)window.clearTimeout(tOut);
var el=document.getElementById('sAnswer');
if(bOK){
el.innerHTML=getCookie(CookieName);
}else{
el.innerHTML=NoResponse;
}
}


function getCookie(sName) {

var dc = document.cookie;
var arrC=dc.split(";");
var tc;
var retVal="No value"

for(x=0;x<arrC.length;x++){
tc=arrC[x].split("=");
tc[0]=tc[0].replace(" ","")
if(tc[0]==sName)retVal = unescape(tc[1]);
}

return retVal;
}

</SCRIPT>
</HEAD>
<BODY>
<input type="text" size=20 id='vInput' value="blah">
<A href="#"
onclick="doIt(document.getElementById('vInput').value);return false">
Call</a><br />
<span id='sAnswer'></span>
</BODY>
</HTML>
 
V

von

Thanks Tim.

I sent you an email.

What I am actually doing is generating a small amount of data via the
Javascript - for example an IP address (though that is not it) and then I
want to send that piece of information to a log - that can be viewed via a
URL.

The script works great when outputting this info to the screen - but I want
it sent to a file to store.

I don't really want it writing back to the screen so the response is not
necessary. I also want this completely invisible to the user.

Thanks for all your input Tim. :)


-Von


Tim Williams said:
This is a bit rough but will allow you to send moderate amounts of data
and get back a status response.

Tim


<HTML>
<HEAD>
<TITLE>Cookie Remote Scripting</TITLE>

<SCRIPT type="text/javascript">

var ErrorTimeoutSec=1.5;
var CookieName="cTest";
var tOut=null;
var NoResponse="No response";
var sImage=null;

function doIt(sMsg){
delCookie(CookieName);
var sURL="getInfo.asp?v="+escape(sMsg)+"&x="+escape(new Date());
sImage=new Image();
sImage.onload=function(){showMsg(true)};
tOut=window.setTimeout("showMsg(false)", ErrorTimeoutSec*1000);
sImage.src=sURL;
}

function delCookie(key){
var d = new Date();
d.setDate(d.getDate() - 2);
document.cookie = key+'=deleted; expires='+d.toGMTString()+';';
}


function showMsg(bOK){
sImage=null;
if(tOut)window.clearTimeout(tOut);
var el=document.getElementById('sAnswer');
if(bOK){
el.innerHTML=getCookie(CookieName);
}else{
el.innerHTML=NoResponse;
}
}


function getCookie(sName) {

var dc = document.cookie;
var arrC=dc.split(";");
var tc;
var retVal="No value"

for(x=0;x<arrC.length;x++){
tc=arrC[x].split("=");
tc[0]=tc[0].replace(" ","")
if(tc[0]==sName)retVal = unescape(tc[1]);
}

return retVal;
}

</SCRIPT>
</HEAD>
<BODY>
<input type="text" size=20 id='vInput' value="blah">
<A href="#" onclick="doIt(document.getElementById('vInput').value);return
false"> Call</a><br />
<span id='sAnswer'></span>
</BODY>
</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top