What's new

Closed How do i update my data table without refreshing page.

Status
Not open for further replies.

Heizengberg

Eternal Poster
Joined
Jul 12, 2017
Posts
597
Reaction
120
Points
282
mga sir tinatry ko kasi na mag mag update yung data table ko without refreshing the page using ajax. bali ang gnawa ko is gumawa ako ng interval na kada 5 seconds ipeperform niya ajax function sa pagkuha ng data . nagana naman sya sir kaso parang may error na nalabas sabi:

Uncaught TypeError: $(...).DataTable is not a function
at HTMLDocument.<anonymous> (<anonymous>:3:19)
at mightThrow (VM4282 jquery-3.3.1.js:3534)
at process (VM4282 jquery-3.3.1.js:3602)

ano kaya to mga sir?

eto nga pala codes ko:

sa page1:

<H1>Get data to table witout refreshin page</H1>
<div id="table_content"></div>

<link rel="stylesheet" type="text/css" href="You do not have permission to view the full content of this post. Log in or register now."/>

<script src="You do not have permission to view the full content of this post. Log in or register now."
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script type="text/javascript" src="You do not have permission to view the full content of this post. Log in or register now."></script>

<script type="text/javascript">



function getData(){
//
$.ajax({
type: 'get',
datatype: 'text',
url: 'norefreshPHP1.php',
success: function(data){
$('#table_content').html(data)
}
})
//
}

getData();
setInterval(function(){
getData() // this will run after every 5 seconds
}, 5000);
</script>

---------------------------------------------------------------------------

sa norefreshPHP1.php naman

<?php
include("connections.php");

// eto yung mismong pagkuha ng mga data para sa table
$query= "SELECT * FROM TBL_USER";
$result=mysqli_query($connections, $query);
?>
<link rel="stylesheet" type="text/css" href="You do not have permission to view the full content of this post. Log in or register now."/>

<script src="You do not have permission to view the full content of this post. Log in or register now."
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script type="text/javascript" src="You do not have permission to view the full content of this post. Log in or register now.
jquery.dataTables.min.js"></script>

<table id="tableuser" class="table order-column table-striped stripe table-bordered">
<thead>
<tr>
<td>UserID</td>
<td>Username</td>
<td>Password</td>
<td>Security Question</td>
<td>Security Answer</td>
</tr>
</thead>
<?php
while ($row=mysqli_fetch_array($result)) {
echo
'<tr>
<td>'.$row["UserID"].'</td>
<td>'.$row["username"].'</td>
<td>'.$row["password"].'</td>
<td>'.$row["squestion"].'</td>
<td>'.$row["sanswer"].'</td>
</tr>';
}
?>
</table>

<script type="text/javascript">
$(document).ready(function() {
$('#tableuser').DataTable();
});
</script>

 
<script type="text/javascript">
$(document).ready(function() {
$.noConflict();
$('#tableuser').DataTable();
});
</script>

Try mo pag May pareho pa din error remove mo yung mga import mo sa norefresh.php (css/js)
 
n
<script type="text/javascript">
$(document).ready(function() {
$.noConflict();
$('#tableuser').DataTable();
});
</script>
Try mo pag May pareho pa din error remove mo yung mga import mo sa norefresh.php (css/js)

nung nilagay ko yung $.noconflict mat error na $ is not a function sir
 
Status
Not open for further replies.

Similar threads

Back
Top