473,804 Members | 3,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XMLHttpRequest. onreadystatecha nge Method Not Running

Hi All,

I'm having a problem with a web app I'm writing. I have a form for
which I'm going to validate one of the fields. I use AJAX to retrieve
XML containing a list of valid entries. My app works under IE, oddly
enough. But, under Firefox, it seems that the
XMLHttpRequest. onreadystatecha nge method is not being called. The
code follows. I'm using synchronous mode because I'm thinking that I
want that global variable g_groupListXML to contain
xmlHttp.respons eText before ajaxGetGroupUse rListXML( ) returns. Am I
right on this point?

function getXMLHTTPReque stObject( )
{
var xmlHttp = null;
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 xmlHttp;
}
var g_groupListXML = null;

function ajaxGetGroupUse rListXML(url)
{
var xmlHttp = null;
xmlHttp = getXMLHTTPReque stObject( );
xmlHttp.onready statechange = function ()
{
if
(xmlHttp.readyS tate == 4)
{

alert("onreadys tatechange called...");

g_groupListXML = xmlHttp.respons eText;
}
}
xmlHttp.open("G ET", url, false);
xmlHttp.send(nu ll);
}

function getGroupListXML (form)
{
var retval = false;
var xmlDoc = null;
var doc = null;

ajaxGetGroupUse rListXML('XMLPr oducingScript.c fm');

// Parse retrieved XML
if (window.ActiveX Object)
{
doc = new ActiveXObject(" Microsoft.XMLDO M");
doc.async = "false";
doc.loadXML(g_g roupListXML);
}
else
{
var parser = new DOMParser( );
doc = parser.parseFro mString(g_group ListXML, "text/xml");
}

xmlDoc = doc.documentEle ment;
form.fieldx.val ue = trim(form.field x.value);

for (var i = 0; i < xmlDoc.childNod es.length; i++)
{
if (xmlDoc.childNo des[i].childNodes[0].nodeValue.toLo wer( ) ==
form.group_name .value.toLowerC ase())
{
alert('String already used');
retval = true;
break;
}
}
return retval;
}

Mar 28 '07
10 11420
Hi All,

Problem solved!! With the aid of Firebug (God bless the makers of
Firebug!!!), I was
able to determine that the global variable set by the
onreadystatecha nge handler wasn't being set at all. I think there
must be a scope issue with that global variable. At least in Firefox
and Netscape anyway. Firebug showed me that responseText was clearly
populated with the data I expected. Firefox seems to have been
differentiating between the global g_groupListXML and the local one in
the handler.

var g_groupListXML = null;
function ajaxGetGroupUse rListXML(url)
{
var xmlHttp = null;
xmlHttp = getXMLHTTPReque stObject( );
xmlHttp.onready statechange = function ()
{
if (xmlHttp.readyS tate ==
4)
{
g_groupListXML =
xmlHttp.respons eText;
}
};
xmlHttp.open("G ET", url, false);
xmlHttp.send(nu ll);
}

Apr 6 '07 #11

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

Similar topics

5
1835
by: Börni | last post by:
Dear group, i have some experience with javascript, but now i am trying to do object oriented programming with it and i am somehow stuck. I have tried the code so far only in Mozilla 1.7.3 I am trying to make an object which offers the functionaltity of the xmlhttpRequest object ( my object is something like a wrapper ). the constructor makes an new XMHttpequest object, and then there are methods to POST or GET data. The problem: I...
20
2698
by: chris.schwalm | last post by:
This is part II of this <a href="http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/cd54951e0ea277de/639c67f2f7cadb1f?tvc=2&q=Simple+HTML+read%2Fwrite+question#639c67f2f7cadb1f"> post</a>. I am creating a java script that bascially reads a webpage - forwards it to an external program/parser/servlet - then overwrites the webpage with a slightly modify version. Basically I have two questions: (1) Do I need to set my...
42
34251
by: Greg | last post by:
Hi, I've designed a bookmark in Ajax / PHP that I will put soon on sourceforge.net. But I've got an very tricky bug. I try it on some computers with Internet Explorer/Windows, Firefox 1.07/Linux, Firefox 1.5/Linux, Firefox 1.5/Windows and Firefox 1.5/Mac, Safari/Mac. It works perfectly on a lot of configurations but, on some PC with Firefox 1.5/Windows (not all), the Javascript code with XmlHttpRequest
25
11305
by: Matt Kruse | last post by:
According to HTTP/1.1 specs, a client should only have two connections open to the host at a time (which can be changed by browser users, of course). When using xmlHttpRequest connections, is there any way to detect that the request is queued? I did some tests (see "Queued Requests" at http://www.ajaxtoolbox.com/request/examples.php ) and it looks like readyState 1 is fired immediately after the request is made, even though it's not...
1
4184
by: mathewda | last post by:
Hey, I'm having a problem that I consider kinda weird that is alluding me at the moment. I've wrote some code that will set up an XMLHttpRequest, it then makes a call to open and send and sets the onreadystatechange to another function of mine. onreadystatechange checks the ready state and if the ready state is 4 and the status is 200 it assigns to the innerHTML of a div. I also have some code that uses the attachEvent method so that all...
2
21878
by: petermichaux | last post by:
Hi, I thought it is about time I tried writing some JavaScript with XMLHttpRequest instead of just using the Yahoo! UI library. The simple page below works in both Safari and Opera but I don't see the alert in Firefox. Looking in Firefox's firebug plugin, I see that the request is successfully sent and the correct response is received. Any ideas what is wrong? Thank you,
1
2267
by: weston | last post by:
So, the following apparently works as a method of grafting a method onto an object (using the squarefree JS shell): obj = { x: 1, inc: null } result obj.inc = function () { this.x++ } result function () { this.x++; } obj.inc() obj.x result 2
5
15512
by: HugeBob | last post by:
Hi All, I've got a question about Asynchronous vs Synchronous mode with the XMLHttpRequest object. What are the ramifications of using one mode vs the other? If the script uses Asynchronous mode, it sounds as if a thread retrieves the data from the supplied URL and the JS function that called the open() and send() methods continues on. Where as using Synchronous mode the method that called open() and send() waits until the data from...
0
9706
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
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10577
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...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10077
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
9150
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
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
5521
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...

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.