注意:未定义索引 ajax
Notice: Undefined index ajax
所以我有一个工作的 zurb-foundation 模态,我还有一个 ajax 代码,每隔 x 秒刷新一次 div。这是代码
index.php
<a class="th [radius]" href="view-comments.php?ilid=<?= $img['img_id']; ?>" data-reveal-id="viewCommentModal" data-reveal-ajax="true">View</a>
查看-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>
加载-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>";
}
?>
我的问题是每次加载 load-comments.php 时,都会显示错误 Undefined index: ilid in D:\wamp\www\instalike\load-comments.php on line 4
。我该如何解决这个问题?谢谢!
你可以用load()
传递参数,你错过了在这里传递ilid
如果你想把它作为GET
传递,你可以这样做
$(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)
});
//加载-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';
}
}
?>
所以我有一个工作的 zurb-foundation 模态,我还有一个 ajax 代码,每隔 x 秒刷新一次 div。这是代码
index.php
<a class="th [radius]" href="view-comments.php?ilid=<?= $img['img_id']; ?>" data-reveal-id="viewCommentModal" data-reveal-ajax="true">View</a>
查看-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>
加载-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>";
}
?>
我的问题是每次加载 load-comments.php 时,都会显示错误 Undefined index: ilid in D:\wamp\www\instalike\load-comments.php on line 4
。我该如何解决这个问题?谢谢!
你可以用load()
传递参数,你错过了在这里传递ilid
如果你想把它作为GET
传递,你可以这样做
$(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)
});
//加载-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';
}
}
?>