AJAX加载无法正常工作

时间:2016-06-25 15:49:04

标签: javascript php jquery css ajax

我正在尝试根据来自外部php文件数据的数据更新html中的选取框,条件是数据库更改。

我的代码无效。

HTML

<p class="scroll marquee"><span></span></p>

如果数据库中有任何最近的更改,则只应更新上述标记。

检查php中的最新更改

<?php
require_once('connect.php');

$json = []; // The JSON array which will be returned
$stmt = $conn->prepare("SELECT COUNT( * ) AS count
FROM `mallscrolls` 
LEFT JOIN malls ON malls.m_Id = mallscrolls.`M-Ids` 
WHERE mallname = 'C Mall' && time_insert > NOW( ) - INTERVAL 25 
SECOND ");
$stmt ->execute();
$row = $stmt ->fetch();
$update = $row['count'] > 0;
$updtstatus =  json_encode(array('count'=>$update));
?>

Ajax将每隔几秒检查一次更新

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
function scrollhandler() {
$.getJSON("check_time_scroll.php", function(update) {
    if (update.count===true) {
     $('#scroll marquee').load('unifoscrolltext.php');
    } 
});
}
setInterval(scrollhandler, 10000);
</script>

'unifoscrolltext.php'

<?php
require_once('connect.php');
$stme= $conn->prepare("SELECT message
FROM `mallscrolls` 
LEFT JOIN malls ON malls.m_Id = mallscrolls.`M-Ids` 
WHERE mallname = 'C Mall' && time_insert > NOW( ) - INTERVAL 30 
MINUTE");
$stme->execute();
while($resultst = $stme-> fetch()){
$message = $resultst["message"];
echo "$message";
}
?>

CSS

<style>
/* Make it a marquee */
.marquee {
width: 100%;
margin: 0 auto;
white-space: nowrap;
overflow: hidden;
background-color: #000000;
bottom: 0px;

}

.marquee span {
display: inline-block;
padding-left: 100%;
text-indent: 0;
animation: marquee 20s linear infinite;
background-color: #000000;
color: white;
bottom: 0px;
}

/* Make it move */
@keyframes marquee {
0%   { transform: translate(0, 0); }
100% { transform: translate(-100%, 0); }
}

/* Make it pretty */
.scroll {
padding-left: 1.5em;
position: fixed;
font: 50px 'Verdana';
bottom: 0px;
left: 0px;
height: 10%;
}
</style>

我错过了什么吗?

0 个答案:

没有答案