473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

AJAX Woes - XML HTTP Request not returning a value

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=workin g;
}
http.open("GET", url, true);
xmlHttp.send(null);
}
}

Feb 22 '07 #1
5 2431
salvador wrote:
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=workin g;
}
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=workin g;
}
http.open("GET", url, true);
xmlHttp.send(null);

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 22 '07 #2
On Feb 22, 7:13 am, Martin Honnen <mahotr...@yahoo.dewrote:
salvador wrote:
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=workin g;
}
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=workin g;
}
http.open("GET", url, true);
xmlHttp.send(null);

--

Martin Honnen
http://JavaScript.FAQTs.com/

Hey Martin,

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

-Sal

Feb 22 '07 #3
VK
On Feb 22, 6:03 pm, "salvador" <spera...@progressivetrail.orgwrote:
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>

Feb 22 '07 #4
On Feb 22, 12:44 pm, "VK" <schools_r...@yahoo.comwrote:
On Feb 22, 6:03 pm, "salvador" <spera...@progressivetrail.orgwrote:
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.
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/
>
or alternately, offer better (read:working) solution?

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

Feb 22 '07 #5
On Feb 22, 2:35 pm, "salvador" <spera...@progressivetrail.orgwrote:
On Feb 22, 12:44 pm, "VK" <schools_r...@yahoo.comwrote:
On Feb 22, 6:03 pm, "salvador" <spera...@progressivetrail.orgwrote:
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.

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/
or alternately, offer better (read:working) solution?
AjaxRequest by Matt Kruse <http://www.ajaxtoolbox.com>
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?

Feb 23 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sure | last post by:
Hello All, I want to update a form using the LWP & HTTP method. It was working fine when I am updating the values like this $ua = LWP::UserAgent->new; $url...
5
by: J Lake | last post by:
I am working on a simple orderform script to keep a running total, however I am encountering some errors. function CalculateTotal() { var order_total = 0 // Run through all the form fields...
3
by: Peter Rilling | last post by:
I am writing a webcrawler, so to speak, and for some reason, this one particular type of page on a site is returning a 400 (bad request), but I can view the page in IE. Other pages on the site...
5
by: Peter Afonin | last post by:
Hello, I have two ASP.NET test sites located on two different Windows 2003 servers: http://testdomain.com.shared-servers.com/ http://web-algorithm.com Both pages have dead links - Folder 1...
1
by: cyber0ne | last post by:
I'm a bit new to PHP. One thing I'm trying to do right now is send an HTTP request and read the response in the code. For an example of what I'm talking about, see this: ...
5
by: rpjanaka | last post by:
Hi all, I am using AJAX to submit a data from a web page, it is properly working on the local host (when test with the local machine it is ok).also when access from another machine the pages are...
1
by: nrohan | last post by:
I'm not much familiar with Java Script. So I just wanted to know that can JavaScript provides capability to modify HTTP request to be sent to the server. I would like to modify few HTTP request...
4
by: gaya3 | last post by:
Hi All, Pl any one say the difference between ordinary Http Request and XmlHttp Request in Ajax Thanks in advance. -Hamsa
4
omerbutt
by: omerbutt | last post by:
hi there i am making an application in which i have a drop down menu which onchange passes a value(this.value) to a js function which gets the value and calls an ajax routine and passes that value...
6
by: SAL | last post by:
hello, I'm using a radiobuttonlist in an updatepanel in an item template in a Gridview control. I'm populating the radiobuttonlist in the RowDataBound event. I have the control toolkit registered...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.