Demon Demon - 8 months ago 46
PHP Question

javascript notification checker script Uncaught Reference Error

I have this notification checker and i don't know whats wrong with this js code, i have errors on checkMessage() : Uncaught Reference Error: checkMessage is not defined

the js code:

function checkMessage(){

if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

xmlhttp.onreadystatechange=function() //when the request is submitted...
if (xmlhttp.readyState==4 && xmlhttp.status==200 //...and everything is ok...
if(xmlhttp.responseText>0){ // if the response text is greater than 0

document.title="("+xmlhttp.responseText+")"+"My Social Network - Welcome";

document.getElementById('checkMsg').innerHTML="<b>" + xmlhttp.responseText+" Notifications</b>";
document.title="My Social Network - Welcome";

document.getElementById('checkMsg').innerHTML="No notifications";

the checkmessage.php code:

include 'dbm.php'; //database settings from an external file

$user = $_SESSION['user'];

$get_count_messages = mysql_query("SELECT message FROM notifications ");
$row = mysql_num_rows($get_count_messages); // count how many rows the query returned

echo "$row"; //return the value

The html code:


<script type="text/javascript" src="notifications.js"></script>
<script type="text/javascript">
setInterval("checkMessage()", 1000);
<div id="checkMsg"></div>


I think your setInterval function should look like:

setInterval(checkMessage, 1000);

Because setInterval expect a function as parameter.