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

93
Views
Sending parameters with xmlhttprequest

Im trying to send paramaters with xmlhttprequest but I dont know how. I have an html code with a form and where I create the xmlhttprequest objet and a php code where I want to send the parameters of my form and show them. So, the thing is that it show me the Notice: Undefined variable error, as the variables are not correctly sent. Both codes are in my xampp/htdocs folder.

These are the codes:

HTML & JS:

<!DOCTYPE html>
<html lang="en">
<head>
   
</head>
<body>

    
    <form name="ajax" method="post">
        
        
        
        Surname: <input id="surname" type="text" required/>
        <br>    
        <br>                  
        Name: <input id="name" type="text" required />
        <br>      
        <br>        
        Phone: <input id="phone" type="tel" required/>
        <br>         
        <br>     
        <input type="submit" value="Send" name="send">

    </form>

      <script>
            
            var surname=document.getElementById("surname");
            var name=document.getElementById("name");
            var phone=document.getElementById("phone");

            var xhttp = new XMLHttpRequest();

            

            xhttp.onreadystatechange = function (){

            if (this.readyState == 4 && this.status==200){
                document.write(this.response);
            }
            };
            xhttp.open("GET","http://localhost/htdocs/show.php surname="+surname+"&name="+name+"&phone="+phone,false);
            xhttp.send();
            
      </script>
</body>
</html>

PHP called "show.php":

<?php


$surname;
$name;
$phone;


echo $surname."<br>".$name."<br>".$phone;


?>

Thank you in advance

about 4 years ago · Juan Pablo Isaza
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!