【发布时间】:2014-05-21 11:11:05
【问题描述】:
如果下面的 php 脚本返回高于 0 的 mysql 选择计数结果,我有以下 javascript 应该向用户弹出通知:
<script>
$(document).ready(function() {
function update() {
$.ajax({
type: 'POST',
url: '../ajax/alert/notification.php',
timeout: 1000,
success: function(data) {
$("#notification-alert-main").text(data);
$("#notification-alert-detailed").text(data);
if (data > 0) {
$("#notification-alert-message").innerHTML('<i class="fa fa-warning danger"></i> New alert has been detected');
}
window.setTimeout(update, 5000);
},
});
}
update();
});
</script>
php 脚本:
<?php
include('../../db.php');
$queryCountUnreadAlerts = $bdd->prepare("SELECT COUNT(*) Nb FROM exp_alert WHERE ale_read = 0;");
$queryCountUnreadAlerts->execute();
$dataCountUnreadAlerts = $queryCountUnreadAlerts->fetch();
$queryCountUnreadAlerts->closeCursor();
echo(intval($dataCountUnreadAlerts['Nb']));
?>
网络浏览器向我报告错误:
[Error] TypeError: 'undefined' is not a function (evaluating '$("#notification-alert-message").innerHTML('<i class="fa fa-warning danger"></i> New alert has been detected')')
success (index.php, line 230)
l (jquery.min.js, line 4)
fireWith (jquery.min.js, line 4)
k (jquery.min.js, line 6)
(anonymous function) (jquery.min.js, line 6)
我怀疑变量类型有误,但我仍然一直在使用整数。
【问题讨论】:
-
innerHTML是DOM节点属性,不是jQuery方法,使用.html('...')
标签: javascript php jquery mysql ajax