in reply to submit data without reload
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: submit data without reload
by bigup401 (Pilgrim) on Jan 22, 2019 at 15:50 UTC | |
by poj (Abbot) on Jan 22, 2019 at 16:06 UTC | |
by bigup401 (Pilgrim) on Jan 23, 2019 at 11:55 UTC | |
by bigup401 (Pilgrim) on Jan 23, 2019 at 17:34 UTC | |
by poj (Abbot) on Jan 23, 2019 at 21:25 UTC | |
|