Configure HTML/JavaScript

Sunday, May 23, 2010

sending ajax request

function selectState(e)
{
if(e==212)
{
//document.getElementById("countryLvl").innerHTML = "";
document.getElementById("stateLebel").innerHTML = "County : ";
document.getElementById("state").innerHTML = "";
//document.getElementById("countryLvl").innerHTML = "";

}
else
{
document.getElementById("stateLebel").innerHTML = "State : ";
if(xmlHttp)
{
try {
xmlHttp.open("GET","SelectState.php?country="+e, true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
} catch(e) {
alert("Can't connect to server:\n" + e.toString());
}
}
}
}

/*function selectCity(e)
{
var myDivLebel = document.getElementById("cityLebel"); //.innerHTML;
myDivLebel.innerHTML = "City : ";

if(xmlHttp)
{
try {
var country = document.getElementById("countryId").value;
xmlHttp.open("GET","SelectState.php?country="+country+"&state="+e, true);
xmlHttp.onreadystatechange = handleServerResponseCity;
xmlHttp.send(null);
} catch(e) {
alert("Can't connect to server:\n" + e.toString());
}
}
}*/

function handleServerResponse()
{
myDiv = document.getElementById("state");
// display the status o the request
/* if (xmlHttp.readyState == 1)
{
myDiv.innerHTML = "Request status: 1 (loading)
";
}
else if (xmlHttp.readyState == 2)
{
myDiv.innerHTML = "Request status: 2 (loading)
";
}
else if (xmlHttp.readyState == 3)
{
myDiv.innerHTML = "Request status: 3 (loading)
";
}
else*/ if (xmlHttp.readyState == 4)
{
// continue only if HTTP status is "OK"
if (xmlHttp.status == 200)
{
try {
response = xmlHttp.responseText;
//myDiv.innerHTML += "Request status: 4 (complete). Server said:
";
myDiv.innerHTML = response;
} catch(e) {
alert("Error reading the response: " + e.toString());
}
}
}
}

function handleServerResponseCity()
{
myDiv = document.getElementById("city");
/* if (xmlHttp.readyState == 1)
{
myDiv.innerHTML = "Request status: 1 (loading)
";
}
else if (xmlHttp.readyState == 2)
{
myDiv.innerHTML = "Request status: 2 (loading)
";
}
else if (xmlHttp.readyState == 3)
{
myDiv.innerHTML = "Request status: 3 (loading)
";
}
else*/ if (xmlHttp.readyState == 4)
{
// continue only if HTTP status is "OK"
if (xmlHttp.status == 200)
{
try {
response = xmlHttp.responseText;
//myDiv.innerHTML += "Request status: 4 (complete). Server said:
";
myDiv.innerHTML = response;
} catch(e) {
alert("Error reading the response: " + e.toString());
}
}
}
}

in reference to: Google (view on Google Sidewiki)

No comments:

Post a Comment