Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

306
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda