Can I Pass JavaScript Variables To A CGI Perl Program

Can I Pass JavaScript Variables To A CGI Perl Program


  • 7 Dec, 2011

    This question has been asked a few times so I felt it was time to include it in the FAQ. The only way to pass information from the client-side (in the JavaScript variable) to the server-side (the Perl program) is through the CGI. Since a CGI application is stateless, it does not remember anything about how it was last called between invocations. Once it stops running, all its variables are forgotten. In order to submit information to a CGI script from a JavaScript variable, you must dynamically create a URL pointing to the CGI program which submits your JavaScript variable. Your CGI script must be set up to respond to submissions using the GET method, since this is the only one you can use when submitting a variable as part of a URL. Take a look at the following bit of code:var firstname = 'Smith'; // JavaScript variable containing firstnamevar URL = eval('http://www.server.com/cgi-bin/script.pl?firstname=' + firstname);document.location.href = URL;and when your script is run (because of the document.location.href statement), your script will have access to the firstname variable.

    Comments Received:
    Please give your suggestions and feedback:

2009-2016 downloadmela.com. All rights reserved.