...

View Full Version : Resolved Transfer javascript variable to bash script



jonhen
01-17-2012, 10:40 PM
I have this code to prompt for text input and then I want to run script.sh:


<script type="text/javascript">
function runscript()
{
var x=prompt("Enter text:");
//this is where I'm lost
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","/cgi-bin/script.sh");
xmlhttp.send()
}
</script>

Is it possible to substitute x above as the value for $txt in script.sh which looks like this below and how please?


#!/bin/bash

echo "Content-type: text/html"
echo ""

<some xmlrpc command> "add text $txt"


:confused:

felgall
01-18-2012, 01:14 AM
You need to pass the value either using GET or POST and then read it in from that spot on the server.

If you use GETthe javaScript to send the value would be:

xmlhttp.open("GET","/cgi-bin/script.sh?x="+encodeURI(x));

jonhen
01-18-2012, 08:01 PM
Thanks for the input.

Well I tried that but I can't get script.sh to read x. I've checked my Apache2 error log and there's nothing showing up other than the deliberate errors I put in to make something show up. I know the script works but maybe something I'm not doing right.

It's almost as if it's working but x is being missed.

:confused:

felgall
01-18-2012, 08:30 PM
You might need to ask about how to read in the querystring in a forum that deals with that server side language.

jonhen
01-18-2012, 09:49 PM
Yes I believe your right. Thanks for getting me this far. I have tried a number of things but with no success.

:)

Jon

jonhen
01-19-2012, 04:44 PM
Just to add, the method I used to solve this problem was to change my script.sh to perl with a few extra lines which together with your line of code suggested yesterday solved my problem.

Thanks.

Jon



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum