Click to See Complete Forum and Search --> : return value from server to client
wind0965
02-02-2004, 10:37 AM
I confront a problem to return a value from server side to client after execute the .cgi. And the cgi is written in C.
I don't know if it is possible to do like:
--in C file (save as "test.cgi"):
int main()
{
.....
return result;
}
--in JavaScript:
var test_cgi = 0;
...
test_cgi = "test.cgi" //OR: test_cgi = return test.cgi
It seems not to work.
Or if there are other possibilities?
Thank you in advance!
Jeff Mott
02-02-2004, 11:40 AM
http://www.codingforums.com/showthread.php?s=&threadid=32574
wind0965
02-02-2004, 12:12 PM
So, you mean it is not possible to do that?
And another question, I wrote in C:(save as "test.cgi")
static int psTest()
{
char* option;
int flag;
option = getenv("QUERY_STRING");
if(option != NULL)
sscanf(option,"%d",&flag);
...
}
and in JavaScript:
var test_cgi = 0;
"test.cgi?" + test_cgi;
But I can not receive the test_cgi as parameter in C. That is flag is always 13784, and option is "*\p001". Do you have any idea?
Thank you!
Scriptage
02-03-2004, 08:26 PM
To get a variable into javascript you need to do the following:
(Example uses Perl but it's the same principle);
In HTML:
<script source="cgi/bin/test.cgi"></script>
In test.cgi:
#!/usr/bin/perl -w
use CGI qw(:all);
use strict;
print header(type=>'text/javascript');
# Do your workings and such here:
my $x = param('some_number');
$x+=10;
print<<EOF;
var myVariable = $x;
EOF
1;
All this does is tell the browser you are outputting javascript, the writing the javascript back to the HTML page with the variable inside.
Regards