jquery - DataTables not recognizing data -


i'm trying insert data datatable.

i have following code:

datatable:

<table id="ladder" class="table table-striped table-bordered" cellspacing="0" width="100%">     <thead>          <tr>             <th>place</th>             <th>team name</th>             <th>w - l</th>             <th>strk</th>             <th>exp</th>             <th>level</th>          </tr>      </thead>      <tbody id="ladder_stats">       </tbody> </table> 

the jquery:

function fillladder(place, name, w, l, strk, exp, lvl, id, ladder) {      $('<tr><td>' + place + '</td><td><a href="/team?id=' + id + '&l=' + ladder + '">' + name + '</a></td><td>' + w + ' - ' + l + '</td><td>' + strk + '</td><td>' + exp + '</td><td>' + lvl + '</td></tr>').appendto('#ladder_stats'); }  function refreshladder() {      var ladder = $.urlparam('l');      $.ajax({        url: '/data/ladder_stats.php',         data: {l: ladder},         datatype: 'json',         type: 'post',         success: function(json) {              console.log(json);              (i = 0; < object.keys(json).length; i++) {                  fillladder(json[i].place, json[i].name, json[i].wins, json[i].losses, json[i].strk, json[i].exp, json[i].level, json[i].id, ladder);             }          },         error: function(ts) {             console.log("error: " + ts.responsetext);         }     }); }   $(document).ready(function() {      refreshladder();     $('#ladder').datatable();     $('#match_finder').datatable(); }); 

as can see code, i'm inserting data table before load datatable() function. unfortunately datatables not recognize data.

enter image description here

based on code, believe due timing. ajax call take while, moving datatables call success should work. updated this.

function fillladder(place, name, w, l, strk, exp, lvl, id, ladder) {      $('<tr><td>' + place + '</td><td><a href="/team?id=' + id + '&l=' + ladder + '">' + name + '</a></td><td>' + w + ' - ' + l + '</td><td>' + strk + '</td><td>' + exp + '</td><td>' + lvl + '</td></tr>').appendto('#ladder_stats'); }  function refreshladder() {      var ladder = $.urlparam('l');      $.ajax({        url: '/data/ladder_stats.php',         data: {l: ladder},         datatype: 'json',         type: 'post',         success: function(json) {              console.log(json);              (i = 0; < object.keys(json).length; i++) {                  fillladder(json[i].place, json[i].name, json[i].wins, json[i].losses, json[i].strk, json[i].exp, json[i].level, json[i].id, ladder);             }              //rows created, can make tables             $('#ladder').datatable();             $('#match_finder').datatable();          },         error: function(ts) {             console.log("error: " + ts.responsetext);         }     }); }   $(document).ready(function() {      refreshladder(); }); 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -