Sending requests to server

This is a demo for sending GET and POST requests to the server. Both requests are handled by the same PHP script ajax2.php shown below.

Enter your name and age

Your name:
Your age:

Server response

PHP script ajax2.php

<?php
$name = "??";
$age = "??";
if (isset($_POST["name"]))    # get user's response
  $name = $_POST["name"];     # with the POST method
if (isset($_POST["age"]))
  $age =  $_POST["age"];

if (isset($_GET["name"]))
  $name = $_GET["name"];      # get user's response
if (isset($_GET["age"]))      # with the GET method
  $age =  $_GET["age"];

$method = isset($_POST["name"]) ? "POST" : "GET";

header("Content-Type: text/html");
print("Hello, {$name}! Your age is {$age}  (Method: {$method})"); 
?>