AJAX Woes - XML HTTP Request not returning a value

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);
}
}
 
M

Martin Honnen

salvador said:
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);
}
}

Move the open and send call out of the onreadystatechange handler

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);
 
S

salvador

Move the open and send call out of the onreadystatechange handler

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);


Hey Martin,

Thanks for the suggestion. Apparently, not what the problem was, but
I'll keep poking at it.

-Sal
 
V

VK

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,

As Martin Honnen pointed out, you script is never executed: remove
open and send out of onreadystatechange handler and place them in the
same block where you create XHR.
or alternately, offer better (read:working) solution?

AjaxRequest by Matt Kruse <http://www.ajaxtoolbox.com>
 
S

salvador

As Martin Honnen pointed out, you script is never executed: remove
open and send out of onreadystatechange handler and place them in the
same block where you create XHR.

Yes. That was a problem with the script. However, it was not the
primary problem that I am encountering. Even using the library that
you recommended below, I cannot get an XHR request to evaluate true.

See for yourself:

http://oregonhomefinder.net/test/
 
S

salvador

Yes. That was a problem with the script. However, it was not the
primary problem that I am encountering. Even using the library that
you recommended below, I cannot get an XHR request to evaluate true.

See for yourself:

http://oregonhomefinder.net/test/

The problem appears to be that the result never gets to a requestReady
state of 4. The transaction appears to be working but always stops at
3.

Why would this be?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top