I'm writing a somewhat simple "Journal" page where I post some entries and people can comment on those entries. This means there are several entries on one page, and below each entry, is a form to post "Comments". After submitting a comment, and clicking a 'submit' button, two things should happen:
1. The PERL script /cgi-bin/hello_world.pl should execute.
2. The person should remain on the page (i.e. no page reload) and the content they put in the form should become an actual comment. (Appear as text above the input fields)
In the past, when submitting forms, I've simply used the format
<form class='frm' name='frm_name_1' id='frm_name_1' action='/cgi-bin/h +ello_world.pl' method='POST'>
and then in my PERL code, I've accessed the parameters simply by using the code
use CGI; use locale; $query = new CGI; $CommentText = $query->param('txt_content');
However, because I want the user to remain on the page and not have the page submit, instead of using a simple form POST method, I learned (through a lot of online searching) that I should be using jQuery instead -- which I have never used before. So, instead of my usual form code, I am using this instead:
<form class='frm' name='frm_name_1' id='frm_name_1' action='' method=' +POST'>
leaving the action parameter blank. And I have then added this script to the HTML page
<script type="text/javascript" src="http://code.jquery.com/jquery- +1.4.2.min.js"></script> <script type="text/javascript" src="http://ajax.microsoft.com/ajax +/jquery.validate/1.7/jquery.validate.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('.frm').submit(function() { $.post('/cgi-bin/hello_world.pl'); return false; }); }); </script>
(Note, I don't really need to do any validations on the fields, I just need them submitted as is)
The problem is, that when I switch from doing the normal form POST, to this jQuery post -- the method that I am used to using in PERL to access the variables isn't working anymore.
use CGI; use locale; $query = new CGI; $CommentText = $query->param('txt_content');
The variable txt_content remains blank. I'm completely stuck!!
I'd be happy to share the entire code if needed, but hoping it's a straight forward solution. I've looked online and through this forum, but nothing seems to change the outcome. Any help would be greatly appreciated.
Secondary to this, in the jQuery script, after the form submits, I need to call a javascript function (that is already written and working fine) called "rewriteDiv(x)" where x is the name of the form that was just submitted - in this case "frm_name_1"). I know it's not a PERL related question at all -- but If anyone knows their jQuery and could also help me out with this, I'd appreciate it.
In reply to Post from jQuery to Perl - can't access parameters by stuckdev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |