473,626 Members | 3,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.rea dyState==4)'.

Can anyone see where I'm going wrong, or alternately, offer better
(read:working) solution?

function ajaxFunction(qs ) {
//document.getEle mentById("coord s").innerHTM L = 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.XMLHT TP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
url = url + qs;
//document.getEle mentById("coord s").innerHTM L= url;
// verify that URL is property constructed - WORKS
xmlHttp.onready statechange=fun ction()
{
if(xmlHttp.read yState==4)
{
var working=xmlHttp .responseText;
// verify that a value is getting returned as text - FAILS
document.getEle mentById("coord s").innerHTML=w orking;
}
http.open("GET" , url, true);
xmlHttp.send(nu ll);
}
}

Feb 22 '07 #1
5 2446
salvador wrote:
xmlHttp.onready statechange=fun ction()
{
if(xmlHttp.read yState==4)
{
var working=xmlHttp .responseText;
// verify that a value is getting returned as text - FAILS
document.getEle mentById("coord s").innerHTML=w orking;
}
http.open("GET" , url, true);
xmlHttp.send(nu ll);
}
}
Move the open and send call out of the onreadystatecha nge handler

if(xmlHttp.read yState==4)
{
var working=xmlHttp .responseText;
// verify that a value is getting returned as text - FAILS
document.getEle mentById("coord s").innerHTML=w orking;
}
http.open("GET" , url, true);
xmlHttp.send(nu ll);

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 22 '07 #2
On Feb 22, 7:13 am, Martin Honnen <mahotr...@yaho o.dewrote:
salvador wrote:
xmlHttp.onready statechange=fun ction()
{
if(xmlHttp.read yState==4)
{
var working=xmlHttp .responseText;
// verify that a value is getting returned as text - FAILS
document.getEle mentById("coord s").innerHTML=w orking;
}
http.open("GET" , url, true);
xmlHttp.send(nu ll);
}
}

Move the open and send call out of the onreadystatecha nge handler

if(xmlHttp.read yState==4)
{
var working=xmlHttp .responseText;
// verify that a value is getting returned as text - FAILS
document.getEle mentById("coord s").innerHTML=w orking;
}
http.open("GET" , url, true);
xmlHttp.send(nu ll);

--

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...@progr essivetrail.org wrote:
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.rea dyState==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 onreadystatecha nge 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...@y ahoo.comwrote:
On Feb 22, 6:03 pm, "salvador" <spera...@progr essivetrail.org wrote:
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.rea dyState==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 onreadystatecha nge 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...@progr essivetrail.org wrote:
On Feb 22, 12:44 pm, "VK" <schools_r...@y ahoo.comwrote:
On Feb 22, 6:03 pm, "salvador" <spera...@progr essivetrail.org wrote:
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.rea dyState==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 onreadystatecha nge 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
5748
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 ='http://xxx.be/cgi-bin/viewauth/Tracking/TestProjectAgainInitialDevStory#edittable2'; use HTTP::Request::Common; my $res = $ua->request(POST $url, Content_Type =>'form-data',
5
2243
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 for (var i=0; i < document.orderform.chkEvent.length - 1; ++i) { // Is the checkbox checked?
3
1089
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 works. Now the issue with this site is that it uses the "referrer" to determine if the proper links were followed. What I don't know is if there are other fields header fields that might be important, or other stuff like cookies. Is there any...
5
1196
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 and Folder 2. However, the behavior is different. When I click on any link on the first page, I get back to the same URL. On the second page I get an error.
1
1999
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: http://www.google.com/apis/maps/documentation/#Geocoding_HTTP_Request Would someone be able to show me a quick example of how to do this in my PHP code? I have a page that gets the "address" value posted to it from a form. Now I need to pass that value to the HTTP...
5
2375
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 properly lord. But when send data it gives an http request error. The following is the error message. it include several suggestions, but i cant exactly deiced what it is.? pls anyone can help me to find the reason for this... ERROR The...
1
1459
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 headers, when a some request(e.g. Get when clicked on some link) is sent to server. Thanks Rohan
4
31989
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
2388
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 to a php page and then takes back the response ,i have done it all but now i was trying to encrypt the information or the string or the value that is passed through the drop down menu and concatinated with the url and passed to that page and then on...
6
2634
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 in the page and I've got code to get the selected value from it in the Radiobuttonlist_SelectedIndexChanged event. The code in there is: Protected Sub rblFMSValue_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
0
8269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8711
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2630
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.