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

181
Views
Reload datatable with javascript and php

Good morning, first of all sorry if I don't ask the question correctly, I'm new and I'm adapting to the community

Currently I have a js-ajax code that, through post, consults me some items to show them in a datable

function fetchItems() {



$.ajax({
  url: 'item-list.php',
  type: 'GET',
  success: function(response) {
   
    
    const project = JSON.parse(response);
    let template = '';
    project.forEach(project => {
      template += `

      <tr Id="${project.id}">
      <td>${project.fecha}</td>
      <td><strong>${project.titulo}</strong></td>
      <td>${project.estado}</td>
      <td>${project.prioridad}</td>
      <td>${project.fechaprevista}</td>
      <td>
      <button type="button" class="btn btn-info btn-sm" Onclick="ShowInfo(${project.id})">Info</button>
      <button type="button" class="btn btn-success  btn-sm" onClick="ShowHis(${project.id})">Añadir seguimiento</button>
      <button type="button" class="btn btn-danger  btn-sm" onClick="Edit(${project.id})"><i class="fa fa-pencil"></i></button>
      </td>
    </tr>
      
    `
    });

  
    $('#list-modulos').html(template);

  
  }

then these items are displayed in the html with the following code

<table id="hiddenrow_desc" class="table table-bordered table-hover display">
                                    <thead>
                                        <tr><th></th>
                                            <th>1</th>
                                            <th>2</th>
                                            <th>3</th>
                                            <th>4</th>
                                            <th>5</th>
                                        
                                        </tr>
                                    </thead>
                                <tbody id="list-modulos">

                        </tbody>
                    </table>

The first call to the fechtask function is correct and is displayed fine, the second and subsequent calls either give an error or the table is not capable of loading, I understand that there must be some method to empty the table and reload it but I do not know

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

0

Try This : I added $('#list-modulos').empty(); line after success to make body empty.

function fetchItems() {

$.ajax({
  url: 'item-list.php',
  type: 'GET',
  success: function(response) {
    
  $('#list-modulos').empty();
    
  const project = JSON.parse(response);
    let template = '';
    project.forEach(project => {
      template += `

      <tr Id="${project.id}">
      <td>${project.fecha}</td>
      <td><strong>${project.titulo}</strong></td>
      <td>${project.estado}</td>
      <td>${project.prioridad}</td>
      <td>${project.fechaprevista}</td>
      <td>
      <button type="button" class="btn btn-info btn-sm" Onclick="ShowInfo(${project.id})">Info</button>
      <button type="button" class="btn btn-success  btn-sm" onClick="ShowHis(${project.id})">Añadir seguimiento</button>
      <button type="button" class="btn btn-danger  btn-sm" onClick="Edit(${project.id})"><i class="fa fa-pencil"></i></button>
      </td>
    </tr>
      
    `
    });

  
    $('#list-modulos').html(template);

  
  }
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!