我有以下的javascript這應該彈出一個通知,如果PHP腳本波紋管返回一個MySQL選擇計數結果大於0的用戶:的Javascript AJAX如果然後其他
<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('...')' –