var xmlHttp var i=0; function showState(str) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="weather2.php" url=url+"?city="+str url=url+"&sid="+Math.random() xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { //s = new String(xmlHttp.responseText); mystring = replace(xmlHttp.responseText,'
','
');
document.getElementById('activeContent').innerHTML = mystring;
}
}
/////////////////////////////////////////////////////
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
/////////////////////////////////////////////////////////
// TIMER
/////////////////////////////////////////////////////////
function start()
{
if(i<=10)
{
showState(i);
i++;
}
else
{
i=0;
showState(i);
}
setTimeout('start()',10000);
}
//////////////////////////////////
// THIS IS A STRING REPLACE FOR IE
//////////////////////////////////
function replace(string,text,by) {
// Replaces text with by in string
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return string;
var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;
var newstr = string.substring(0,i) + by;
if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),text,by);
return newstr;
}
///////////////////////////////////
window.onload = start;