Reputation: 35
I am trying to load my content of a div
continuously from another page but it's not loading.
I have tried with alert
, it worked fine but page data is not loading.
JavaScript
<script>
$(document).ready(function(){
setInterval(function(){$("#loadAvailable").load("update.php");},1000);
});
</script>
update.php
<?php
include '../db.php';
echo "<ul>";
$sql = "SELECT cat, COUNT(*) as num_items, GROUP_CONCAT(id) AS accountID FROM accounts WHERE user = '0' GROUP BY cat";
if($result = mysqli_query($conn, $sql)){
if(mysqli_num_rows($result) > 0){
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<li><a href='#' draggable='false' id='".$row["cat"]."' onclick='Gen(this.id);'>".$row["cat"]." <span class='badge' id='".$row["cat"]."AV'>".$row["num_items"]."</span></a></li>";
}
}
}
echo "</ul>";
?>
HTML code
<h3><b>Choose any option from below</b></h3>
<div class="updateBox">
<h4><div class="title">Available Items</div></h4>
<div class="contents">
<div id="loadAvailable">
</div>
</div>
</div>
</div>
Upvotes: 0
Views: 65
Reputation: 8141
That should work, but you need to add some error checking as it may be the php page that is not working:
$( "#loadAvailable" ).load( "update.php", function( response, status, xhr ) {
if ( status == "error" ) {
alert(xhr.status + " " + xhr.statusText);
}
});
Upvotes: 1