Thank you for your quick response again. I apologize that I'm still not getting it. I'm really sorry. No doubt I'm in over my head at this point, but I'd like to get it figured out and to learn from it.
Based on what you suggested, I did two things (I'm sure neither of which was correct). First, I added the global timer variable into the php file (insertion in bold):
<?php
<strong> var timer = 0; // Declared as global variable.</strong>
//include AjaxTwits and create an object
include('AjaxTwits.php');
$ajaxTwits = new AjaxTwits;
//set the cache to a writable folder, to save xml files
$ajaxTwits->cachefolder = "ajaxtwits/cache";
//the amount of minutes the feed is cached
$ajaxTwits->cacheTime = 2;
//the amount of items you'll show
$ajaxTwits->itemCount = 15;
//add your twitter account feeds
$ajaxTwits->addTimeline("xxxx", "xxxx");
$ajaxTwits->addTimeline("yyyy", "yyyy");
//disable human time and output just Y/m/d date format
$ajaxTwits->humanTime = true;
//this will output the information, JSON is for the Javascript application
$ajaxTwits->outputFeed("json");
?>
Second, I added the script you suggested into my preexisting js as shown below (insertion in bold):
function sendAjaxRequest(url, eventhandler) {
if (window.ActiveXObject) {
var xhr = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
var xhr = new XMLHttpRequest();
}
<strong> xhr.onreadystatechange = function() {
start = setTimeout( this, 1000 );
if ( timer === 5 && xhr.readyState !== 4 ) { // Specify the number of timer limit, it is currently set to 10sec delay.
/* Add the things that you need to process if the requested content failed to load with the given time limit. */</strong>
xhr.onreadystatechange = function() {
if(xhr.readyState == 4)
if(xhr.status == 200) {
eventhandler(xhr);
} else {
document.body.innerHTML = xhr.responseText;
}
}
xhr.open("POST", url, true );
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.send("");
}
function getAjaxTwits(url, itemCount) {
var twitter = document.getElementById('AjaxTwits');
var twitterload = document.getElementById('AjaxTwitsLoader');
sendAjaxRequest(url, function(ajaxRequest) {
if (ajaxRequest.responseText) {
var ans = eval('(' + ajaxRequest.responseText + ')');
if (ans.item) {
twitter.removeChild(twitterload);
for (var i = 0; i < itemCount; i++) {
var li = document.createElement("LI");
li.className = "twitter-item";
var message = hyperlinks(ans.item[i].description);
message = twitter_users(message);
li.innerHTML += "<font color='#D36727'><u>" + ans.item[i].feedname + "</u>:</font> ";
li.innerHTML += message + " [";
var a = document.createElement("A");
// a.href = ans.item[i].url;
a.href = "http://www.twitter.com/" + ans.item[i].user;
a.className = "twitter-link";
// a.innerHTML = "posted " + ans.item[i].date;
a.innerHTML = "<span style='white-space:nowrap;'>" + ans.item[i].date + "</span>";
a.target = "_blank";
li.appendChild(a);
li.innerHTML += "]";
twitter.appendChild(li);
}
}
}
});
function hyperlinks(text) {
text = text.replace(/\s(http:\/\/[a-z][a-zA-Z0-9\/\*\-\?\.\&\%\$]*)/ig," <a href=\"$1\" class=\"twitter-link\" \"target\">$1</a>");
text = text.replace(/\s([a-zA-Z]+:\/\/[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)([\s|\.|\,])/ig," <a href=\"$1\" class=\"twitter-link\" \"target\">$1</a>$2");
// match www.something.domain/path/file.extension?some=variable&another=asf%
text = text.replace(/\s(www\.[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)([\s|\.|\,])/ig," <a href=\"http://$1\" class=\"twitter-link\" \"target\">$1</a>$2");
return text;
}
function twitter_users(text) {
text = text.replace(/([\.|\,|\:|\¡|\¿|\>|\{|\(]?)@{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/ig, "$1<a href=\"http://twitter.com/$2\" class=\"twitter-user\" \"target\">@$2</a>$3 ");
return text;
}
<strong> clearTimeout( start );
xhr.abort();
document.body.innerHTML = "Loading failed!";
return false;
}
if ( xhr.readyState === 4 && xhr.status === 200 ) { //The request completed the execution over its timer limit.
clearTimeout( start );
delete start;
document.body.innerHTML = xhr.responseText;
} ++timer;
}; // Callback reference ENDED.</strong>
}
If you point out where I'm erring, I would really appreciate it! Thanks again!