Solved

onreadystatechange trigger in Firefox 2.0

Posted on 2006-11-23
4
223 Views
Last Modified: 2006-11-24
In an effort to learn about AJAX I found several similar examples and created a demo program.  The problem seems to occur in the segment shown below.
- - - - - - - - - - - - - - - - - - - -
<script language="javascript">

var http = new XMLHttpRequest();

function sndReq(action) {
      http.onreadystatechange = handleResponse;
      http.open('GET', 'ajtestprocessor.php?action='+action, false);
      http.send(null);

</script>
- - - - - - - - - - - - - - - - - - - -
I can insert alert statements and watch http.readyState change from 0 (uninitialized), to 2 (loaded), and then to 4 (complete).  In Firefox 2.0 the onreadystatechange trigger fires only once (on the 0 to 1 transition) while in Opera 9.1 it appears to fire on each transition.  From other languages and from the coding of the AJAX examples, the behavior of Opera is what I would expect.  Is Firefox handling this trigger properly?  Do I need to somehow reset the trigger in the 'handleResponse' function?

Thanks.
0
Comment
Question by:ttheimer
  • 3
4 Comments
 
LVL 7

Expert Comment

by:vbandaru
Comment Utility
If you make the asynchrouns flag to true, it does fire for all states.
0
 
LVL 7

Accepted Solution

by:
vbandaru earned 250 total points
Comment Utility
Okay here is what i found and it makes sense. if the asynchronous flag is set to false as in your case, There is no point in monitoring the ready state. The code just waits untill it recieves a response back (readystate=4) from the send method. The 0to 4 transition is something that cannot be monitored.

I agree that opera and I.E still track that but this seems to be a browser specific  implementation.

Hope that helps!!
0
 
LVL 17

Expert Comment

by:gops1
Comment Utility
I think responding to ready states varies from browser to browser.

You can go to this URL : http://www-128.ibm.com/developerworks/web/library/wa-ajaxintro2/index.html

and refer, HTTP ready states
0
 
LVL 7

Expert Comment

by:vbandaru
Comment Utility
gops1 ,
The article does not describe states when the asynch flag is false.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now