Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

340
Vistas
AJAX updating variables in EJS

I am trying using ajax for the first time. I have a working site and want to make it improve, therefore I dont want to redirect the clients on each post, I want to use AJAX and do a databse call in the backend with node.js.

For HTML I am using EJS. I want to let AJAX get called when the page is loaded. All that is already working.

My problem is, that I am using an if call in EJS.

its like:

if(variableX === 0){
render this header
} else{
render login header with name
}

The function in the backend gets called, but its not going to render the variables in my EJS file.

Can anyone help?

EJS:

  <script type="text/javascript">
  $(document).ready(function() {
    $.ajax({
             type: 'post',
             url: '/',
             dataType: 'text',
             async: false
         })
  });
  </script>  <script type="text/javascript">
  $(document).ready(function() {
    $.ajax({
             type: 'post',
             url: '/',
             dataType: 'text',
             async: false
         })
  });
  </script>

pages.js:

    res.render('home', {
    pageName: "",
    userName: result[0].twitchName,
    isLive: liveStatus,
    userID: result[0].id,
    benachrichtigung: benachrichtigung,
    twitchPBUrl: twitchPBLink
  });
}

Thank you so much in advance :)

The best regards, Joshy

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The point of Ajax is that:

  • You make an HTTP request with JS
  • The response to that request is provided to JS

It does not:

  • Render the response automatically in the browser viewport
  • Travel back in time and change data that was used to create the response that the HTML document you are looking at came from

You can:

  • Submit a <form> instead of using Ajax. The response to a form submission is rendered in the viewport (in the same way that following a link or typing a URL in the address bar is).
  • Write JavaScript to use the response to update the DOM of the current page
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda