am trying to use get method. but i don't want to reload page when i click submit. i want to get response back without reload. my problem is at ajax script tho am not good at ajax. am just starting it. i appreciate for correction
#!/usr/bin/perl -w use JSON::XS; use CGI::Carp 'fatalsToBrowser'; use HTTP::Request::Common qw(POST); use LWP::UserAgent; use Net::SSL; use CGI; use CGI::Pretty ":standard"; $CGI = CGI->new; my $ua = LWP::UserAgent->new; if (param('Submit') eq 'Submit') { my $req = HTTP::Request->new(GET => 'http://jsonplaceholder.typicode.c +om/todos/1'); my $res = $ua->request($req); $respons = JSON::XS->new->decode ($res->content); $userid = $respons->{userId}; $id = $respons->{id}; $title = $respons->{title}; $completed = $respons->{completed}; } print "Content-type: text/html\n\n"; print <<START_HTML; <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" /> <title>Untitled Document</title> </head> <body> <form method="post"> <p>userId: $userid</p> <p>id: $id</p> <p>title: $title</p> <p>completed: $completed</p> <input type="submit" id="Submit" name="Submit" value="Submit"> <p> </p> </form> <script> $(document).ready(function () { $("#Submit").click(function(event) { }); }); function Execute(){ $.ajax({ type: 'POST', url: '/folder/test.pl', data: { 's': }, success: function(res) { alert(res); }, error: function() {alert("failed");} }); }; </script> </body> </html> START_HTML
In reply to submit data without reload by bigup401
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |