Hi, I'm struggling with writng an AJAX query function. It seemed to work in IE and Opera, but not in Firefox - but now won't seem to fire at all.
The page can be seen at: http://localhost/CRITS/index.php. Waht should happen is that as you click on the top left image, changing Home to Business, the text starting Carlton IT Services should change.
This is the function (I know it repeats itself!):
// JavaScript Document
var root = "images/"
var img = 1
function swapImg(img1){
if(img==0){img1.setAttribute('src',root+img+'.gif');
source = "scripts/home.txt";
img++;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("leader").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",source,true);
xmlhttp.send();}
else{img1.setAttribute('src',root+img+'.gif');
source = "scripts/business.txt";
img--;}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("leader").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",source,true);
xmlhttp.send();
}
As I say, it did kinda work - but now just swaps the image.