【发布时间】:2016-02-24 21:14:50
【问题描述】:
我在显示信使的页面上的 <div id="chtmsg"> 中有此代码...
PHP:
if($perguntas){
for($c=0;$c<count($perguntas);$c++){
$perguntas[$c]->tipo == 'F' ? $class = 'message_F' : $class = 'message_P';
$hora = substr($perguntas[$c]->hora, 0, 5);
echo "<li class=\"".$class."\"><p>".$perguntas[$c]->mensagem."</p><span>".$pergunta->databr($perguntas[$c]->data)." - ".$hora."</span></li>";
if($perguntas[$c]->tipo=='F' and $perguntas[$c]->status == 0){
$pergunta->marcaRespLida($perguntas[$c]->id);
}
}
}
效果很好。因此,我想用 js 加载它以仅在 div #chtmsg 内刷新所有新消息,然后我创建了一个文件 msg.php 并使用 <?php include("msg");?> 它继续运行良好,但使用 js 我需要放置路径。 ..
HTML:
$(document).ready(function () {
setInterval(function() {
$.get(hostGlobal+'site/modulos/produto/msg.php', function (result) {
$('#chtmsg').html(result);
scTop();
});
}, 3000);
});
但它显示了 de div 内部的错误...
注意:未定义变量:第 3 行 /Applications/XAMPP/xamppfiles/htdocs/sisconbr-sistema-novo/site/modulos/produto/msg.php 中的 perguntas
我测试了 msg.php 文件中的其他代码,并且在没有变量的情况下可以正常工作...
【问题讨论】:
-
你在哪里定义
$perguntas变量?你能在msg.php里面定义它吗? -
其实你的变量没有定义。如果您在浏览器中调用 php 文件,您将看到相同的消息。您需要在 $.get 查询中将变量作为参数发送。
标签: javascript php mysql variables