I am trying to create a ajax script that checks for updates to a database. right now it runs whiteboard_total.asp which returns a number if that number is larger than the stored var it will update the contents. What I have doesn't update the content, it isn't giving an error. I am very new to ajax so hoping for some insight here. The script:
Code:
var whiteboard_total = 0;
function makeRequest(url) {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = function() { checkTotal(http_request); };
http_request.open('GET', url, true);
http_request.send(null);
setTimeout("makeRequest('whiteboard_total.asp?division=nc')", 5000);
}
function checkTotal(http_request) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
if (whiteboard_total >= 0) {
temp_total = parseInt(http_request.responseText);
if (temp_total > whiteboard_total) {
whiteboard_total = temp_total;
getContent('whiteboard_output.asp?division=nc');
self.focus();
}else{
whiteboard_total = temp_total;
}
}
//alert(http_request.responseText);
} else {
alert('There was a problem with the request.');
}
}
}
function getContent(url) {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = function() { updateContents(http_request); };
http_request.open('GET', url, true);
http_request.send(null);
}
function updateContents(http_request) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
document.getElementById('content').value = http_request.responseText
} else {
alert('There was a problem with the request.');
}
}
}
window.onload=makeRequest('whiteboard_total.asp?division=nc')