Essentially, I am attempting to create a fade in/out popup located in the corner of my webpage. For example, when John Doe logs online, I want a notification to appear. This is achieved by using AJAX to check for new updates and displaying the popup if necessary.
The jQuery function to display the popup is:
function hidepop(){
$("#popup").fadeOut("slow");
}
function showpop(){
$("#popup").fadeIn("slow");
setTimeout("hidepop()",4000);
}
The code responsible for updating and showing the popup is as follows:
function getHTTPObject(){
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX. Please download Google Chrome or Firefox.");
return null;
}
}
function checkUpdates(old){
httpObject = getHTTPObject();
var randomnumber=Math.floor(Math.random()*10000);
if (httpObject != null) {
link = "updates.php?rnd="+randomnumber;
httpObject.open("GET", link , true);
httpObject.onreadystatechange = function() {
if(httpObject.readyState == 4){
var response = httpObject.responseText;
var objDiv = document.getElementById("popup");
objDiv.innerHTML = response;
if(response == old){
var time = setTimeout(function(){checkUpdates(response); response = null},5000);
}else{
var objDiv = document.getElementById("popup");
objDiv.innerHTML = response;
showpop();
var time = setTimeout(function(){checkUpdates(response); response = null},5000);
}
}
}
}
}
To initialize this process, add the following line to the body tag:
onload="checkUpdates('');"
When implemented, nothing appears to occur. Although, I have verified that the popup can be shown successfully by calling showpop(). It seems like there may be a simple mistake causing this issue. Any guidance or suggestions on identifying and resolving the problem would be greatly appreciated.
Thank you, Calum.