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

193
Views
La solicitud GET del nodo no aparecerá en la página html, solo se carga, no devuelve el error

Cuando envío una solicitud route.get desde el servicio, responde correctamente con datos JSON y se muestra en localhost:/ver/página del producto; sin embargo, quiero que procese la página html del lado del cliente y muestre la información de la base de datos en la tabla allí. No está haciendo eso.

Mi objetivo es OBTENER estos datos y mostrarlos en una tabla html simple en la ruta localhost:3000/view/product.

Cualquier consejo sería apreciado, gracias de antemano.

Mi intento de tabla html:

 <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="app.css"> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css"> <div> <header> <h2><a href="/"><i></i> VIEW PRODUCTS </a></h2> </header> </div> </head> <body> <div id="table"> <table align='center' cellspacing=2 cellpadding=5 id="productTable" border=1> <thead> <th> Product Name </th> <th> Quantity </th> <th> Price </th> </thead> <tbody id="productTable"></tbody> </table> </div> </body> </html> <script> $.get('/view/product', {}, function(results) { let res = ''; results.forEach(data => { res += `<tr><td>${data.productname}</td><td>${data.quantity}</td><td>${data.price}</td></tr>` }) $('#place-here').html(res) }); </script>

mi solicitud de obtención:

 route.get("/view/product", async function (req, res) { try { const results = await db.query("SELECT * FROM product ORDER BY createdAt DESC;", ); // console.log(results); // res.status(200).json({ // status: "success", // results: results.rows.length, // data: { // orders: results.rows, // }, // }); } catch (err) { console.log(err); } });

cargando la página html en mi archivo index.js:

 app.get('/view/product',function(req,res){ res.sendFile('view.html', { root: __dirname }); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No puede usar la misma ruta tanto para la carga de su página como para la llamada Ajax para obtener JSON, ya que ambas son rutas GET, por lo que solo el primero registrado con su servidor Express tendrá la oportunidad de ver la solicitud entrante.

Le sugiero que cambie la llamada Ajax a algo como /api/products y luego cambie la definición correspondiente en su servidor para la ruta que devuelve JSON.

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!