Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How many times onreadystatechange property of XMLHTTPREQUEST would be get called?

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following below code is related to AJAX .

can anybody please let me know how many times the function getOutput will be getting called ??




Waiitng for your replies .
Thanks in advance .
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A very simple google search would've landed you here...
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Html/Javascript forum...
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
W3schools offers a better explanation on the ready-state-change here.

To answer your question in particular, it cannot be determined. While transitions between states are defined certain states may trigger the on-ready-state function multiple times (e.g. 3: processing request ).

Note - W3schools mentions that "onreadystatechange event is triggered four times, one time for each change in readyState.", but I remember of some place that onreadystatechange could trigger of multiple times, for the same state.

Usually there is no interest in the other states and the only state that is important is readyState==4 and status==200. Using a Javascript library JQuery, Prototype even hide this and give you simple function to work with like Ajax.Load('page', element)
 
vijin das
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The onreadystatechange event is triggered every time the readyState changes.

The readyState property holds the status of the XMLHttpRequest and Changes from 0 to 4:

The onreadystatechange event is triggered four times, one time for each change in readyState and which are like ...


0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready

In the onreadystatechange event, we specify what will happen when the server response is ready to be processed.

When readyState is 4 and status is 200, the response is ready:
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much .

Javaranch has helped me a lot , how can i help this site in back ??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic