Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
Ajax .post() method doesn't send data to the server

I've got 2 web-pages named test1.html and test1.php. I'm sending some data as key/value pairs using ajax .post() method, but it doesn't seem to reach the server side as I'm getting the following error:

Warning: Undefined variable $name in C:\xampp\htdocs\WebMid2Practice\ajax\test1.php on line 6

Warning: Undefined variable $age in C:\xampp\htdocs\WebMid2Practice\ajax\test1.php on line 7

Here's my code:

test1.html

<!DOCTYPE html>
<html>
    <head>
        <title>Ajax</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" ></script>
        <script>
            $(document).ready(function() {
                $("#load").click(function() {
                    var txtName = $("#name").val();
                    var txtAge = $("#age").val();
                    $.post("test1.php", {name:txtName, age:txtAge}, function(data) {
                        $("#result").html(data);
                    });
                })
                
            });
        </script>
    </head>
    <body>
        <h1>Ajax Practice</h1>
        <div class="result"></div>
        Enter Name: <input type="text" id="name"><br>
        Enter age: <input type="text" id="age"><br>
        <button id="load">Send request to test1.php</button>
        
    </body>
</html>

test1.php

<?php
    if (isset($_REQUEST['name']) && isset($_REQUEST['age'])) {
        $name = $_REQUEST['name'];
        $age = $_REQUEST['age'];
    }
    echo "Name entered is: " .$name;
    echo "Age: " .$age;
?>
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!