Using Ajax to display rotating news items in IE7, using Joomla/VirtueMart/sh404

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
guitarhangar
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Wed Nov 28, 2007 10:16 pm
Contact:

Using Ajax to display rotating news items in IE7, using Joomla/VirtueMart/sh404

Post by guitarhangar » 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).

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
It's really easy to make things complicated- the trick is to make them simple.
http://guitarhangar.com - webmaster
http://www.amediacreative.com - programmer/security (they didn't make the above site)

Post Reply