Alright, so after several days of searching and reading I still can't get this to work so this is kinda my last chance. Keep in mind i'm a rookie with Ajax and JS.
I have a comment wall where you can leave a nice little message to others on the page and it works just fine but now I want to add some ajax so it auto refresh every 10 second and get the latest comments.
The thing is I get the whole website to be displayed inside that div and not the comments.
I have a js document with the following code
(function update() {
$.ajax({
type : 'GET',
url : 'index.php',
success : function(data){
$('#cmt_wall_container').html(data);
},
}).then(function() {
setTimeout(update, 10000);
});
})();
And my Index.php page include the following
<?php include_once 'connect.php'; ?>
<?php
$cmt_list = "";
$sql = mysqli_query($con, "SELECT * FROM cmt ORDER BY id DESC LIMIT 10");
$cmtCount = mysqli_num_rows($sql);
if($cmtCount > 0){
while($row = mysqli_fetch_array($sql)){
$id = $row["id"];
$comment = $row["comment"];
$cmt_list .="<div class='post-container'><p class='post-comment'>$comment</p></div>";
}
} else {
$cmt_list = "leave a comment";
}
?>
<head>stuff..</head>
<body>
<div id="cmt_wall_container">
<?php echo $cmt_list; ?>
</div>
</body>
I hope this is clear enough! Thank you very much in advance, you are really my last hope!!!!!