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

229
Views
How to Update DataTable with JSON data in Javascript?

I have a table TableElements and a Javascript valiable jsonData. I want to reload TableElements' dataTable using the reload() method but without success.

The goal is to add a row to the table, inserting it into the database. This is the code I used so far

 $.ajax({
                    url: 'AddRow.php',
                    type: 'POST',
                    data: { 
                        CatProg: catProg,
                        CatUser: catUser,
                        CatPass: catPass,
                        CatInUso: catInUso,
                        CatDesc: catDesc,
                        CatUltimo: catUltimo,
                        CatDat: catDat
                    },
                    dataType: "text",
                    success: function(result){
                    // draw table again
                        var table = document.getElementById('TableElements');
                        table.remove();
                        var tableContainer = document.getElementById('tableContainer');
                        tableContainer.innerHTML = result;

                        jsonData = GetJsonFromTable(); // it works

                        $('#TableElements').DataTable({ ajax: 'data.json' }).reload(); //?? how to put 'jsonData' here?


                    },
                    error: function(){
                        alert("Request did not succeed. Reload and try again.");
                    }
                });
            }

This is what jsonData is holding:

[
  {
    "Aggiungi": "Modifica Elimina",
    "CatProg": "1",
    "CatUser": "user1",
    "CatPass": "user1pass1",
    "CatInUso": "Y",
    "CatDesc": "desc",
    "CatUltimo": "1",
    "CatDat": "12-12-2001"
  },
  {
    "Aggiungi": "Modifica Elimina",
    "CatProg": "2",
    "CatUser": "admin",
    "CatPass": "admin",
    "CatInUso": "N",
    "CatDesc": "aaa",
    "CatUltimo": "1",
    "CatDat": "01-01-1999"
  }
]
about 4 years ago · Santiago Trujillo
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!