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

343
Views
how to get an answer? (no page reload)

the server sends a response. I don't understand how to process it. If you get "json" opens a page with array. If you get "res.render" refreshes the page. How can I get json and process it.

// express.js

if (!errors.isEmpty()) {          
    if (errors.array().find(el => el.param === 'login')) {
        //1 version
        res.status(409).json({
            message: 'Error login'
        })
        //2 version
        res.render('reg', {
            isReg: true
        })
    } 
}
 
 <!-- Handlebars -->
 <form class="login-form" action="/reg" method="POST" >
    <div class="form-group">
        <label for="exampleInputEmail1" class="text-uppercase">Login</label>
        <input type="text" class="form-control" id="validationLogin" name="login" placeholder="" required>
    </div>
        <div class="block-login d-flex justify-content-center">
        <button type="submit" class="btn btn-login float-right">Submit</button>
    </div>
</form>

<!-- how to get an answer?  -->

<script>
//example
var answer = res.json
</script>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you use res.json then the end point will return JSON. This is designed to be consumed with some custom code and not by being loaded directly into the browser. You could make an Ajax request and then insert data from the result into the DOM. This is how you get the result without loading a new page.

If you use res.render then then end point will return whatever you render, which is almost always HTML. This is a new page. You are expected to pass the data as the second argument to render and then process it with the view engine you have selected (handlebars in this case).

e.g.

<p>{{isReg}}</p>
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!