Using Ajax to display rotating news items in IE7, using Joomla/VirtueMart/sh404
Posted: Thu Dec 20, 2007 10:40 pm
Hi:
I'm a beginner with AJAX, just graduated, and I'm attempting to get my website to display rotating news items in a compact frame: essentially there are news items in a SQL database, and I am using setTimeout() to change the news item every 5 seconds [code below]:
This is an included .js file in the .html document (which is a "module" that uses Jumi).
This works on all browsers except for IE7. On IE7, sometimes when I click another link on my website, Internet Explorer tells me that it cannot view the webpage, and displays an error, and clears the web browser viewing space. However-the website is displayed in the background before the error appears.
Which got me to thinking:
I believe what is happening in these circumstances is that I am clicking a link outside of the AJAX module while a xmlHTTPObject request was being handled by my PHP script- and then the PHP script fires off its reply, and "confuses" IE7.
I tried to remedy the problem by using clearTimeout(controller) in a function that was within the scope of controller, activated whenever the page was unloaded, but to no avail. For refrence, this was done in the tag of my template , ie:
Does anyone have any suggestions about how to remedy this or what might be going wrong?
Thanks very much in advance,
Stew
I'm a beginner with AJAX, just graduated, and I'm attempting to get my website to display rotating news items in a compact frame: essentially there are news items in a SQL database, and I am using setTimeout() to change the news item every 5 seconds [code below]:
This is an included .js file in the .html document (which is a "module" that uses Jumi).
Code: Select all
function switchNews(newsitem,loop){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Unfortunately, your browser won't be able to view all of the information on our website. Please upgrade to IE5.5, Safari 1.1, FireFox, Opera 8.0, Netscape 7 or higher to be able to see our entire site! ");
return;
}
//This sets a global var "stopped" which will act as a "synchronizer". If loop and stopped are both true, the script
//doesn't make the query.
if(!loop){
stopped=true;
}
//This escapes out of the function if a user has clicked a link.
if(loop && stopped){
return;
}
lastitem = currentnews;
currentnews = newsitem;
var url="includes/jumies/gh_news.php";
url=url+"?newsitem="+newsitem;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
//This loops the news until the user has clicked a specific link.
if(!stopped){
if(currentnews == 5){
nextnews = 1;
}
else{
nextnews = currentnews + 1;
}
controller = setTimeout('switchNews(' + nextnews + ',1)',5000);
}
}
This works on all browsers except for IE7. On IE7, sometimes when I click another link on my website, Internet Explorer tells me that it cannot view the webpage, and displays an error, and clears the web browser viewing space. However-the website is displayed in the background before the error appears.
Which got me to thinking:
I believe what is happening in these circumstances is that I am clicking a link outside of the AJAX module while a xmlHTTPObject request was being handled by my PHP script- and then the PHP script fires off its reply, and "confuses" IE7.
I tried to remedy the problem by using clearTimeout(controller) in a function that was within the scope of controller, activated whenever the page was unloaded, but to no avail. For refrence, this was done in the tag of my template , ie:
Does anyone have any suggestions about how to remedy this or what might be going wrong?
Thanks very much in advance,
Stew