See here. You need to escape (\) the $ in the javascript and add jquery.js. Also you need to show the code for test.pl because more errors could be there.
#!/usr/bin/perl use strict; use warnings; print "Content-type: text/html\n\n"; print <<END_HTML; <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" /> <title>Untitled Document</title> <script src="jquery-3.1.1.min.js"></script> <script> \$(document).ready(function () { \$("#Submit").click(function(event) { Execute(); }); function Execute(){ \$.ajax({ type: 'POST', url: 'test1.pl', data: { 's': '' }, success: function(res) { alert(res.msg); }, error: function() { alert("failed"); } }); }; }); </script> </head> <body> <input type="button" id="Submit" name="Submit" value="Submit"/> </body> </html> END_HTML
poj#!/usr/bin/perl # test1.pl use strict; use JSON; use CGI; my $q = new CGI; my $json = encode_json( { msg => "Time now is ".localtime } ); print $q->header( -type => 'application/json' ),$json;
In reply to Re: submit data without reload
by poj
in thread submit data without reload
by bigup401
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |