• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

onreadystatechange trigger in Firefox 2.0

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
ttheimer
Asked:
ttheimer
  • 3
1 Solution
 
vbandaruCommented:
If you make the asynchrouns flag to true, it does fire for all states.
0
 
vbandaruCommented:
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
 
gops1Commented:
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
 
vbandaruCommented:
gops1 ,
The article does not describe states when the asynch flag is false.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now