gpt4 book ai didi

php - 通知: Undefined index ajax

转载 作者:行者123 更新时间:2023-11-29 07:37:22 25 4
gpt4 key购买 nike

所以我有一个工作 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>

查看评论.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">&#215;</a>
</html>

加载评论.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 时,它都会显示错误第 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

<?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';
}
}

?>

关于php - 通知: Undefined index ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30287549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com