S
salvador
I'm trying to create a function to return some values from a php
script. The php script is returning the correct values if called from
a browser window. However, the function that I'm using never appears
to pass the condition 'if(xmlHttp.readyState==4)'.
Can anyone see where I'm going wrong, or alternately, offer better
(read:working) solution?
function ajaxFunction(qs) {
//document.getElementById("coords").innerHTML = qs;
// check to see that value is being passed - WORKS
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
url = url + qs;
//document.getElementById("coords").innerHTML= url;
// verify that URL is property constructed - WORKS
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
var working=xmlHttp.responseText;
// verify that a value is getting returned as text - FAILS
document.getElementById("coords").innerHTML=working;
}
http.open("GET", url, true);
xmlHttp.send(null);
}
}
script. The php script is returning the correct values if called from
a browser window. However, the function that I'm using never appears
to pass the condition 'if(xmlHttp.readyState==4)'.
Can anyone see where I'm going wrong, or alternately, offer better
(read:working) solution?
function ajaxFunction(qs) {
//document.getElementById("coords").innerHTML = qs;
// check to see that value is being passed - WORKS
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
url = url + qs;
//document.getElementById("coords").innerHTML= url;
// verify that URL is property constructed - WORKS
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
var working=xmlHttp.responseText;
// verify that a value is getting returned as text - FAILS
document.getElementById("coords").innerHTML=working;
}
http.open("GET", url, true);
xmlHttp.send(null);
}
}