Guys I have a data coming from an outsource table which I'm presenting in table. The original data coming in Json which I'm decoding using PHP function and displaying.
I have been googling for auto refreshing that data and found this Auto refresh table without refreshing page PHP MySQL
I have managed to built what is suggested in the Ticked answers and seems like working for the first time but it doesn't refresh. So when page is loaded
I'm calling this
$(document).ready (function () {
var updater = setTimeout (function () {
$('div#user_table').load ('get_new_data', 'update=true');
/* location.reload(); */
}, 1000);
});
Which loads a function named get_new_data from controller file and loads on to
<div class="container-fluid" id="user_table">
</div>
Codeigniter controller function is
public function get_new_data(){
$url = 'https://gocleanlaundry.herokuapp.com/api/users/';
$result = $this->scripts->get_data_api($url);
$data_row = $result;
$tbl = '';
$tbl .= '<table class="table table-striped table-responsive" id="tableSortableRes">
<thead>
<tr>
<th>Name</th>
<th>Email Address</th>
<th>Role</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>';
foreach($data_row as $row){
$tbl .= '<tr class="gradeX">
<td>' . $row->name . '</td>
<td>' . $row->email . '</td>
<td>' . $row->role . '</td>
<td><p id="' . $row->_id. '_status">'.( $row->alive == true ? 'Active' : 'Banned').' </p></td>
<input id="' . $row->_id . 'status_val" value="' . $row->alive . '" type="hidden">
<td class="center">
<a href="#" id="' . $row->_id . '_rec" onclick="UpdateStatus(' . $row->_id . ')" class="btn btn-mini ">'
. ($row->alive == '1' ? '<i class="fa fa-thumbs-o-up fa-fw"></i>' : '<i class="fa fa-thumbs-o-down fa-fw"></i>' ) . '</a>
</td>
</tr>
';
}
$tbl .= '</tbody>
</table>';
echo $tbl;
}
As I said when page loads is showing data so something is working but when I add new data to the database is doesn't automatically show up. I want function to call and refresh the data. Sorry I'm very new to javascript and jQuery so please go easy on me :)
Thank you guys