TEST.PL
#!/usr/bin/perl -w
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="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery
+.min.js"></script>
<script>
\$(document).ready(function () {
\$("#Submit").click(function(event) {
Execute();
});
function Execute(){
\$.ajax({
type: 'POST',
url: 'te.pl',
data: { 's': '' },
success: function(res) {
\$('#result').text(res.msg);
},
error: function() {
alert("failed");
}
});
};
});
</script>
</head>
<body>
<form method="post">
Fullname: <input type="text" name="fname"><br>
<p id="result" >Name Is:</p>
<input type="button" id="Submit" name="Submit" value="Submit"/>
</form>
</body>
</html>
END_HTML
TE.PL
#!/usr/bin/perl -w
use JSON;
use CGI;
my $q = new CGI;
my $name = $q->param("fname");
my $json = encode_json(
{ msg => $name }
);
print $q->header( -type => 'application/json' ),$json;
|