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

238
Visualizações
How can I pass parameter from 1 HTML page to another HTML page with AJAX?

This is my first page.

<!DOCTYPE html>
<html>
<head>
    <title>Student List</title>
</head>
<body>
        <h1>Customer Form</h1>
        <form>
        <div>
            <label>Customer Name:</label>
            <input type="text" autofocus id="name">
        </div>
        <br>
        <div>
            <label>Address:</label>
            <input type="text" id="address">
        </div>
    <button  type="button" onclick="myFunction()">Submit</button>
        </form>
    
    <!-- JavaScript -->
    <script type="text/javascript" src="./javascript.js"></script>
</body>
</html>

This is my second page.

<!DOCTYPE html>
<html>
<head>
    <title>Student List</title>
</head>
<body>
        
    <p id="1"></p>
        
    <!-- JavaScript -->
</body>
</html>

MY JAVASCRIPT

function myFunction() {
    const xhttp = new XMLHttpRequest();
    xhttp.onload = function(){
        name = document.getElementById('name').value;
        address = document.getElementById('address').value;
        document.getElementById("1").innerHTML="<h1>alola="+name+"</h1>";
        document.getElementById("2").innerHTML=address;
    }
    xhttp.open("GET", name);
    xhttp.send();
}

I would like to display my name when typing my name from first page in the customer name label, and when i click submit. my second page display my name in the "id=1".

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Ajax and ajax like techniques (fetch etc.) are usually used to either post data to a form or to get data from a url.

To send data from one HTML page to another you would need some kind of database and server side code to capture and store it and later retrive it.

If you just want inputed client side data to persist across pages then look at sessionStorage or localStorage, for example to keep the name we type until we exit the browser or clear session data:

First page:

<form>
        <div>
            <label>Customer Name:</label>
            <input type="text" autofocus id="name">
        </div>
        <br>
        <div>
            <label>Address:</label>
            <input type="text" id="address">
        </div>
    <button  type="button" onclick="">Submit</button>
        </form>
<script>
  const name=document.getElementById('name')
  name.addEventListener("keyup", (e) => {
      
  sessionStorage.setItem('uname', name.value);
});
</script>

Second page:

<body>
        
  <p id="usersName"></p>
  <script>
    let userNameElm = document.getElementById('usersName');
    userNameElm.innerText = sessionStorage.getItem('uname');
  </script>   
</body>

Just remember to be careful what you store, and that it's only stored on the frontend/client side.

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