Reputation: 13462
So I have a working zurb-foundation modal and I also have an ajax code that refreshes the div every x number of seconds. Here is the code
index.php
<a class="th [radius]" href="view-comments.php?ilid=<?= $img['img_id']; ?>" data-reveal-id="viewCommentModal" data-reveal-ajax="true">View</a>
view-comments.php
<script>
$(document).ready(function(e) {
setInterval(function() {
$('#load-comments').load('load-comments.php');
}, 3000)
});
</script>
<body>
<div id="load-comments"></div>
</body>
<a class="close-reveal-modal">×</a>
</html>
load-comments.php
<?php
require 'dbc.php';
$stmt = $dbc->prepare("SELECT * FROM tbl_comments WHERE img_id=:imageid ORDER by c_id DESC");
$stmt->bindValue(':imageid', $_GET['ilid']);
$stmt->execute();
foreach ($stmt as $data) {
extract($data);
echo "<b>{$c_message}</b>";
}
?>
My problem is that every time the load-comments.php is being loaded, it shows the error Undefined index: ilid in D:\wamp\www\instalike\load-comments.php on line 4
. How can I resolve this? Thanks!
Upvotes: 0
Views: 315
Reputation: 38542
You can pass parameter with load()
, you missed to pass ilid
here
if you want pass it as GET
you can do like this
$(document).ready(function(e) {
var ilid=25; //change ilid as per your need or move it to setInterval
setInterval(function() {
$('#load-comments').load('load-comments.php?ilid=ilid');
}, 3000)
});
//load-comments.php
<?php
require 'dbc.php';
if(isset($_GET['ilid'])){
$stmt = $dbc->prepare("SELECT * FROM tbl_comments WHERE img_id=:imageid ORDER by c_id DESC");
$stmt->bindValue(':imageid', $_GET['ilid']);
$stmt->execute();
foreach ($stmt as $data) {
extract($data);
echo "<b>{$c_message}</b>";
}else{
echo 'Missing ilid';
}
}
?>
Upvotes: 2