我正在尝试更新包含的 PHP 文件并从该文件中获取刷新的结果和变量。文件 getmssg.php
包含在 foreach 循环中,因为我需要在该文件中有一个行值。我从文件 getmssg.php
中获取的变量 $ergebnis1
。
如何在不重新加载页面的情况下调用/刷新包含的 PHP 文件的查询值?
<?php
include("chatmain.php");
?>
<?php foreach ($result2 as $key => $row): ?>
<?php include("getmssg.php"); ?>
<li data-icon="false" name="listi5" class="listitem5">
<a type="button" class="ui-btn" id=5">
<?php if ($ergebnis1 > 0) {
echo '<span class="ui-li-count">'.$ergebnis1.'</span>';
} ?>
</a>
</li>
<?php endforeach; ?>
我现在拥有的:
function getmsg() {
$.ajax({
url: 'getmssg.php',
type: 'post',
success: function(output) {
//alert(output);
}
});
}
var timer;
function docount() {
timer = setInterval(function(){
getmsg();
}, 3000);
}
docount();
最佳答案
尝试将 php forEach 放在一个 php 函数中,并在 ajax 的成功回调中调用该函数。它将在没有页面加载的情况下更新内容
关于javascript - 从包含的 php 文件中刷新查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35720904/