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

121
Views
¿Es posible pasar mi valor en el nodo y expresar js haciendo clic en un botón?

En este problema, quiero pasar mis valores en express js para que se escriban en el nodo js. Estoy haciendo clic en un botón que será la demostración aquí

 <form action="/measure" method="POST"> <button type="button" name="Add" > Add </button> <button type="button" name="Substract" > Subtract </button> <input type="submit"> </form>

Hice algo como esto en express js

 const homePage = fs.readFileSync('./index.html') app.get('/',(req,res) => { res.writeHead(200,{'content-type':'text/html'}) res.write(homePage) res.end() }) var counter = 0; app.post('/measure',(req,res) => { res.writeHead(200,{'content-type':'text/html'}) const {Add,Subtract,result} = req.body if (Add) { counter += 1; } else if (Subtract) { counter -= 1 } res.write(homePage + `<h1>${counter}</h1>`) res.end() })

Pero esto no hace nada, según mi pensamiento, el error aquí es el botón en el índice html que no pasa nada... ¿Tienen alguna idea de cómo puedo pasar el valor en el express js? He estado buscando desde anoche pero no pude encontrar la información correcta. Todo lo que obtengo es este enlace que no es mi preferido ya que aún no me estoy enfocando en la base de datos ENLACE

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

0

Un solo botón en un formulario se puede representar como un elemento <button> . Pero si quiere varios botones en un formulario, represéntelos todos como <input type="submit"> :

 <form action="/measure" method="POST"> <input type="submit" name="Add" value="Add"/> <input type="submit" name="Subtract" value="Subtract"/> <input type="submit"/> </form>

Dependiendo del botón que presione, obtendrá req.body como

  • {"Add": "Add"} o
  • {"Subtract": "Subtract"} o
  • {}
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!