jquery - Automatically refresh table from included .php file -


i have been trying table refresh without page being refreshed. know can done ajax can't seem working.
situation:
have main.php page has include (table.php). include contains table id: tablevisit. table dynamically being made: loops through every row in database. table.php

echo "<div id='tablecontainer'>";    $con = new mysqli("localhost","sample","samplepass","sample");    $sql = "select * sampletable"; $i = 0;  $dyn_table = '<table border="1" cellpadding="10" class="visitorlist" id="tablevisit">';   $query = $con->query($sql);  while($row = $query->fetch_assoc()){         $id = $row['id'];         $name = $row['address'];         $date = $row['date'];         $time = $row['time'];         $url = $row['visit_url'];         $urlstring = $row['visit_url'];           if($i % 3 == 0){              $dyn_table .= '<tr><td>'.$name.'</td>';             $dyn_table .= '<td>'.$date.'</td>';             $dyn_table .= '<td>'.$time.'</td>';             $dyn_table .= '<td class="tdshort"><a href='.$url.' target = "_blank" class=" tdoverflow">' . $_session['cuttedurl'] . '</a></td>';             $dyn_table .= '<td><button type= "button" name = "' . $id . '"  class="dynamixbutton navbar-button btn-danger btn" post_id="' . $id . '" type="submit" >chat</button></td>';             $dyn_table .= '<td>' . $id . '</td>';           }         else {             $dyn_table .= '<tr><td>'.$name.'</td>';             $dyn_table .= '<td>'.$date.'</td>';             $dyn_table .= '<td>'.$time.'</td>';             $dyn_table .= '<td><a href='.$url.' target = "_blank" class=" tdoverflow">' . $_session['cuttedurl'] . '</a></td>';             $dyn_table .= '<td><button type= "button" name = "' . $id . '" class="dynamixbutton navbar-button btn-danger btn" post_id="' . $id . '" type="submit">chat</button></td>';             $dyn_table .= '<td>' . $id . '</td>';          }         $i++;      } $dyn_table .='</tr></table>';  echo "</div>"; 

on main.php echo $dyn_table; called. now, $dyn_table needs called every x seconds. how 1 this? i've tried refreshing table thought better call $dyn_table every x seconds.
i've tried this, this , this did not work out me. , html elements, not php variables. suggestions? recommendations, tips?
in advance!

as far understand question believe got no clue on how ajax works. maybe might you.

in pseudo code looks this:

whenajaxrequestwassuccessfull (var tabledata = getdatafromserverviaajax('http://url of php file echos json formated data string')) {    var dataobject = convertjsontoobject(tabledata);    loop on table {     tablerow->tablefield->setdata(dataobject->somedetail)    }  } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -