Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

307
Vistas
Refresh only portion of page (td) after perform database update query (Mysql), using Express (node js)

i'm new to node js and express. I need to refresh only a portion of page (a td in table or the whole table) after perfoming a database update query using express. So in this way i'll show the updated value for the td without refreshing the whole page. The update query is performed by click an <a> element. Thank you.

Here some code i use:

Html from index.ejs page:

<thead>
<tr><th>Goals</th></tr>
</thead>
<tbody>
        <%
        if(userData.length!=0){
        var i=1;
        userData.forEach(function(data){
        %>
<tr>
<td><a href="add-goal?id=<%= data.id %>"><i class="bi bi-plus-circle-fill text-success"></i></a><span class="badge bg-primary rounded-pill"><%=data.goals%></span></td>
</tr>
        <%  i++; }) %>
        <% } else{ %>
          <tr>
            <td colspan="10">No Data Found</td>
        </tr>
        <% } %>
<tbody>

Select Query to database:

router.get('/players-list', (req, res, next) => {
    db.query('SELECT * FROM players_list ORDER BY goals DESC;', (err, data, fields) => {
    if (err) throw err;
});
});

Update Query to database:

router.get('/add-goal', (req, res, next) => {
  db.query('UPDATE players-list SET goals = goals + 1 WHERE id = ?', req.query.id, (err, data) => {
    res.redirect('players-list');
  });
});

P.S. It doesn't make much difference if i refresh the td, the tr or the whole table.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda