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

180
Views
Publicar y luego cambiar el texto en html nodejs

Tengo una etiqueta de formulario en Html como entonces:

 app.get("/",(req,res)=>{ res.sendFile(__dirname+"/index.html")

})

 app.post("/Cong",urlencodedParser,(req,res)=>{ var a = parseInt(req.body.a); var b = parseInt(req.body.b); var c = a + b; res.send("Result: "+c)//This is will route to a new website, but I just want change text in my HTML })
 <form action="/Cong" method="post"> A: <input type="text" name="a"><br> B: <input type="text" name="b"><br> <label id="result"></label> </form>

cómo puedo cambiar la etiqueta en HTML con id resultado = valor C en el archivo js cuando hago clic en el botón.

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

0

Mirando su código, estoy un poco confundido acerca del contexto en el que está tratando de lograr esto.

En el navegador, haría document.getElementById("result").innerHTML = c

Pero no muestra el código del front-end, solo el back-end, necesitaría llamar a su punto final del back-end desde el front-end

por ejemplo: publicar en /Cong aquí hay un ejemplo en Axios

 axios.post('/Cong', { a: 1, b: 2 }) .then(function (response) { document.getElementById("result").innerHTML = response; }) .catch(function (error) { console.log(error); });

Su backend res.send("Result: "+c) también debe leer res.send(c) ya que, de lo contrario, el front-end obtendrá "Resultado: 3" en lugar de solo 3

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!