Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

94
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda