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

336
Views
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 answers
Answer question

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 Report
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!