473,795 Members | 3,175 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 #1
10 11418
HugeBob wrote:
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?
You don't have to bother with onreadystatecha nge if you make a
synchronous request, just use the responseXML/Text.
--
Ian Collins.
Mar 30 '07 #2
"Ian Collins" <ia******@hotma il.comwrote in message
news:57******** ******@mid.indi vidual.net...
HugeBob wrote:
>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 .onreadystatech ange 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.respon seText before ajaxGetGroupUse rListXML( ) returns. Am I
right on this point?
You don't have to bother with onreadystatecha nge if you make a
synchronous request, just use the responseXML/Text.
Um, if you have to make synchronous calls you need to rethink your AJAX.

http://ajaxblog.com/archives/2005/05...s-requests-bad for just one example.

-Lost
Mar 30 '07 #3
-Lost wrote:
"Ian Collins" <ia******@hotma il.comwrote in message
news:57******** ******@mid.indi vidual.net...
>>HugeBob wrote:
>>>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
XMLHttpReque st.onreadystate change 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.resp onseText before ajaxGetGroupUse rListXML( ) returns. Am I
right on this point?

You don't have to bother with onreadystatecha nge if you make a
synchronous request, just use the responseXML/Text.


Um, if you have to make synchronous calls you need to rethink your AJAX.
Not if it's a call to get information required to carry on, loading an
interface description for example.

--
Ian Collins.
Mar 30 '07 #4
"Ian Collins" <ia******@hotma il.comwrote in message
news:57******** ******@mid.indi vidual.net...
-Lost wrote:
>"Ian Collins" <ia******@hotma il.comwrote in message
news:57******* *******@mid.ind ividual.net...
>>>HugeBob wrote:

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
XMLHttpRequ est.onreadystat echange 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.res ponseText before ajaxGetGroupUse rListXML( ) returns. Am I
right on this point?
You don't have to bother with onreadystatecha nge if you make a
synchronou s request, just use the responseXML/Text.


Um, if you have to make synchronous calls you need to rethink your AJAX.
Not if it's a call to get information required to carry on, loading an
interface description for example.
Very good point! However, causing the UA to block until that information is retrieved is
erroneous.

You can achieve much more efficient results by using an asynchronous call (I mean, come
on, AJAX). Storing the responseText for example, then displaying it where and if, need
be.

In fact, the responseText is normally only available at a readyState of 4, so... I do not
see the *need* of synchronous calls.

-Lost
Mar 30 '07 #5
-Lost wrote:
"Ian Collins" <ia******@hotma il.comwrote in message
news:57******** ******@mid.indi vidual.net...
>>-Lost wrote:
>>>"Ian Collins" <ia******@hotma il.comwrote in message
news:57***** *********@mid.i ndividual.net.. .

You don't have to bother with onreadystatecha nge if you make a
synchrono us request, just use the responseXML/Text.
Um, if you have to make synchronous calls you need to rethink your AJAX.

Not if it's a call to get information required to carry on, loading an
interface description for example.


Very good point! However, causing the UA to block until that information is retrieved is
erroneous.

You can achieve much more efficient results by using an asynchronous call (I mean, come
on, AJAX). Storing the responseText for example, then displaying it where and if, need
be.
It's a tricky problem if you have to set up some preconditions (such as
building an RPC object from a description file) before the AJAX
functionality on the page can be used. You have three choices:

1) Use a synchronous request.
2) Poll to see if the preconditions have occurred.
3) trap the error if an AJAX call is made before the the preconditions
have occurred.

Which you choose probably depends on the environment, I mainly support
intranet applications, so I can take the easy first option.

--
Ian Collins.
Mar 30 '07 #6
"Ian Collins" <ia******@hotma il.comwrote in message
news:57******** ******@mid.indi vidual.net...
-Lost wrote:
>"Ian Collins" <ia******@hotma il.comwrote in message
news:57******* *******@mid.ind ividual.net...
>>>-Lost wrote:

"Ian Collins" <ia******@hotma il.comwrote in message
news:57**** **********@mid. individual.net. ..
>
>You don't have to bother with onreadystatecha nge if you make a
>synchronou s request, just use the responseXML/Text.
Um, if you have to make synchronous calls you need to rethink your AJAX.
Not if it's a call to get information required to carry on, loading an
interface description for example.


Very good point! However, causing the UA to block until that information is retrieved
is
erroneous.

You can achieve much more efficient results by using an asynchronous call (I mean, come
on, AJAX). Storing the responseText for example, then displaying it where and if, need
be.
It's a tricky problem if you have to set up some preconditions (such as
building an RPC object from a description file) before the AJAX
functionality on the page can be used. You have three choices:

1) Use a synchronous request.
2) Poll to see if the preconditions have occurred.
3) trap the error if an AJAX call is made before the the preconditions
have occurred.
1. Based on your intranet usage, this is ideal.

2. No need to poll when using asynchronous calls. As the readyState will update you
regardless of async or sync.

3. You can however use e.target.status if the AJAX returns erronous results based upon
the context of theXMLHttpReque st.

Example:

function onError(e)
{
alert(e.target. status);
}
XMLHttpRequest. onerror = onError; // assuming XMLHttpRequest is a valid XHR Object
Which you choose probably depends on the environment, I mainly support
intranet applications, so I can take the easy first option.
Ah hah! So the implementation defines the use!

Even in an intranet application I would be hard-pressed to not use async calls. However,
I have used synchronous calls based on the fact an intranet application should have
instantaneous results.

-Lost
Mar 30 '07 #7
Hi Ian, Lost

"-Lost" <mi*********@co mcast.netwrote in message
news:wN******** *************** *******@comcast .com...
"Ian Collins" <ia******@hotma il.comwrote in message
news:57******** ******@mid.indi vidual.net...
-Lost wrote:
"Ian Collins" <ia******@hotma il.comwrote in message
news:57******** ******@mid.indi vidual.net...

-Lost wrote:

"Ian Collins" <ia******@hotma il.comwrote in message
news:57***** *********@mid.i ndividual.net.. .

You don't have to bother with onreadystatecha nge if you make a
synchrono us request, just use the responseXML/Text.
Um, if you have to make synchronous calls you need to rethink your
AJAX.
>>>

Not if it's a call to get information required to carry on, loading an
interface description for example.
Very good point! However, causing the UA to block until that
information is retrieved
is
erroneous.

You can achieve much more efficient results by using an asynchronous
call (I mean, come
on, AJAX). Storing the responseText for example, then displaying it
where and if, need
be.
It's a tricky problem if you have to set up some preconditions (such as
building an RPC object from a description file) before the AJAX
functionality on the page can be used. You have three choices:

1) Use a synchronous request.
2) Poll to see if the preconditions have occurred.
3) trap the error if an AJAX call is made before the the preconditions
have occurred.

1. Based on your intranet usage, this is ideal.

2. No need to poll when using asynchronous calls. As the readyState will
update you
regardless of async or sync.

3. You can however use e.target.status if the AJAX returns erronous
results based upon
the context of theXMLHttpReque st.

Example:

function onError(e)
{
alert(e.target. status);
}
XMLHttpRequest. onerror = onError; // assuming XMLHttpRequest is a valid
XHR Object
>
Which you choose probably depends on the environment, I mainly support
intranet applications, so I can take the easy first option.

Ah hah! So the implementation defines the use!

Even in an intranet application I would be hard-pressed to not use async
calls. However,
I have used synchronous calls based on the fact an intranet application
should have
instantaneous results.

-Lost
-Lost, you don't seem to mention any downside or additional
processing/infrastructure that needs to occur if in Async mode:-

.. Do we not have to provide a Cancel_Request (From memory, I think the
method is .abort() for the XHR object?) function?

.. If the user chooses to cancel the request does it really only cancel the
client end and leave the server clocking up cpu cycles and i/o for no good
reason, and the user is now free to kick off another dodgy query>

.. If the user has hit the "Confirm transaction" button do we not have to
make sure to disable that button while the async XHR request is in progress
otherwise the user's bank statement could end up with transferred $1000 no
$2000 nope $3000 Doh!

.. Is it not like CPM and if what the XHR (or other more sensible server
request API) has to provide is on the critical path then there's no point
letting the user continue 'cos the only other valid thing left to do is
click over the clock?

.. In most (a lot? at least some?) cases, is "freeing up the event thread for
the Cancel Button" the only valid reason to go Async? (And if you're not
providing a cancel button then surely the options are limited?)

.. I've seen at least one predictive text thingy that is still providing
Select Lists for the first character entered of a surname while the user has
finished typing :-( And then key 2, key 3. . . (But admittedly I'm certainly
not arguing that the user should wait 2secs between keystrokes while a
synchronous request gets the matching list :-)

I suppose my question is, "What is this multi-tasking that you'd have the
user do while they're waiting for a response?"

Cheers Richard Maher

PS. Not being able to close the window (without the "Program is not
responding" crap) is certainly a bummer.

Mar 31 '07 #8
Richard Maher wrote:
>
PS. Not being able to close the window (without the "Program is not
responding" crap) is certainly a bummer.
Which is no different from a "regular" desktop application that's
waiting for a repose to come back from something that has become mute.

--
Ian Collins.
Mar 31 '07 #9
Hi Ian,

Ian Collins wrote:
Which is no different from a "regular" desktop application that's
waiting for a repose to come back from something that has become mute.
I didn't know this was a global desktop issue; so I guess no disadvantage
there then either.

But to be fair to -Lost, surely one big disadvantage of serialized
synchronous requests occurs if/when the opportunity for multiple parallel
requests arises (Struggling for an example this early, but let's say
"Roll-up sales figures from the five regional offices") Given that there are
no/few concurrency and locking issues due to the seperate remote databases,
a near linear improvement in performance can be achieved by using Asynch XHR
and kicking all the request off at once, and then sitting at a barrier until
they all come back.

I personally use Sockets with blocking Sends with a variation on subsequent
Blocking Recvs: - I supply a SetSoTimeout(ms ecs) method so that a lengthy
query may return several zero-byte (my flag to indicate timeout) receives
and then give the event thread enough time to process things, like "cancel"
or "Working. . ." message, before rescheduling (setTimer("read Socket()",0))
another read. Once the result-set has started coming back then I
setSoTimeout(ba ckToNormalXmsec s). [But then XHR won't talk to you until the
entire/complete/unmanagably-large result set has been materialized; so why
would anyone using XHR care about parallelism?]

Anyway, what I'd *really* like to know is "How does XMLHttpRequest work?"
How does it provide this Asynchronous Callback or Up-Call, back to the
browser's page? Is (or can) this mechanism be made generic? If I have a
thread running in a Java Applet, can I manufacture a browser-recognizable
event object and instantiate a browser-side fireEvent() method? What is the
API for this?

Does anyone know the inner workings of XMLHttpRequest, and if so can they
please share that information with us/me?

Cheers Richard Maher
Apr 1 '07 #10

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
2696
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
34247
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
11303
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
4183
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
21876
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
2266
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
10436
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
10213
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
10000
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
9040
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
7538
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
6780
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
5436
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3722
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.