Php 注意:未定义的索引ajax
因此,我有一个工作的zurb foundation模式,还有一个ajax代码,每x秒刷新一次div。这是密码 index.phpPhp 注意:未定义的索引ajax,php,jquery,mysql,ajax,pdo,Php,Jquery,Mysql,Ajax,Pdo,因此,我有一个工作的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> view-comments.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>
<?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>";
}
?>
<?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';
}
}
?>
$(文档).ready(函数(e){
setInterval(函数(){
$('#load comments').load('load-comments.php');
}, 3000)
});
×
load-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>
<?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>";
}
?>
<?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';
}
}
?>
我的问题是,每次加载load-comments.php时,它都会在第4行的D:\wamp\www\instalike\load-comments.php中显示错误
未定义索引:ilid。我如何解决这个问题?谢谢 您可以使用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)
});
//load-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>
<?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>";
}
?>
<?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';
}
}
?>
是否启用了短标记?如果没有,请尝试更改Yes,因为它已启用。我知道问题是加载的数据不知道从哪里获取值ilid@FewFlyBy,不客气。很高兴它能帮你,祝你好运:)嘿,我能有个后续问题吗?因此,在我的setInterval(function(){$('#load comments').load('load-comments.php?ilid=ilid');},3000)代码中,如何在加载消息之前添加类似“加载消息…”的消息?Thanks@FewFlyBy在这种情况下,$.ajax
将是优于$.load()
的最佳选择,因为在这种情况下,发送前
,错误
,数据过滤器
,成功
和完成
选项都接受在适当时间调用的回调函数。这将帮助您设置消息,使其易于查看