var xmlHttp //setting a var for the xmlhttp request
function chat(username) //creating the function...
{
xmlHttp=GetXmlHttpObject() //setting the var to a real request
if (xmlHttp==null) //if it cants get the xml object
{
alert ("Browser does not support HTTP Request") //tell the user
return //dont do the rest of the script
} //end of statement
var url="chat.php" //where you want to send ur req to...
url=url+"?q="+username //making it so u can fetch the data
url=url+"&sid="+Math.random() //adding session id
xmlHttp.onreadystatechange=stateChanged //get response
xmlHttp.open("GET",url,true) //send it via get
xmlHttp.send(null)
}
function stateChanged() //function for getting response
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("text").innerHTML=xmlHttp.responseText //change ur div tag's inner html to the response text
}
}
function GetXmlHttpObject() //function to get xml object
{
var xmlHttp=null; //var is equal to nothing.
try //attempt different browsers...
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest(); //<--- for these three browsers set xmlobject to this.
}
catch (e) //if its ie then...
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); //do this
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp; //send xml request to var running it
}