javascript - Loop updating classes instead of id fields -
i'm trying make function can applied multiple instances of class within page refresh data via ajax call. function works fine 1 instance on page:
$(document).ready(function() { function getdata(t, id, table, hid) { var autoload = setinterval(function (){ $(t).load('ajax.php?id='+id+'&table='+table).html(hid); } , 5000); } var elements = document.getelementsbyclassname("refresh"); (var = 0, item; item = elements[i]; i++){ var tableid = $(item).attr('id'); var rid = $(item).data('id'); var rtable = $(item).data('table'); getdata('.refresh', rid, rtable, tableid); console.log(rid + rtable + tableid); } });
the rtable , rid serve determine data pulled ajax w/ php script. in 1 iteration, i'm calling script on table:
<tbody id="files" class="refresh" data-id="10" data-table="files-refresh"> <tr> <td colspan="2"></td> </tr> </tbody>
in second iteration, i'm calling script on div:
<div class="refresh" data-id="10" data-table="timeload" id="content"></div>
the result of files-refresh loads both .refresh classes, overwritten timeload. how modify files-refresh goes #files table , timeload goes #content?
getdata('.refresh', rid, rtable, tableid);
should
getdata(tableid, rid, rtable);
with getdata being
function getdata(t, id, table) { var autoload = setinterval(function (){ $('#' + t).load('ajax.php?id='+id+'&table='+table); } , 5000); }
Comments
Post a Comment