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>&nbsp;</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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.