Questions tagged [readystate]

a property of both Document and XMLHttpRequest objects

readyState is a property of both Document and XMLHttpRequest objects.

Document.readyState

In a Document object, readyState represents the object's loading state. It has three possible values:

  • loading
  • interactive
  • complete

Example

When the readyState value changes, a Document.onreadystatechange event is fired:

document.onreadystatechange = function () {
  if (document.readyState === 'loading') {
    console.log('the document is still loading');
  } else if (document.readyState === 'interactive') {
    console.log('the document has loaded, but sub-resources are still loading');
  } else if (document.readyState === 'complete') {
    console.log('the document and its sub-resources are loaded');
  }
}

XMLHttpRequest.readyState

In an XMLHttpRequest object, readyState represents the current state of the request's lifecycle. It has five possible values:

  • UNSENT (0)
  • OPENED (1)
  • HEADERS_RECEIVED (2)
  • LOADING (3)
  • DONE (4)

Example

When the readyState value changes, a XMLHttpRequest.onreadystatechange event is fired:

var request = new XMLHttpRequest();

request.onreadystatechange = function () {
  if (request.readyState === 1 || 
    request.readyState === XMLHttpRequest.OPENED) { 
    console.log('the request has been successfully opened');
  } else if (request.readyState === 2 || 
    request.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
    console.log('the response headers have been received');
  } else if (request.readyState === 3 || 
    request.readyState === XMLHttpRequest.LOADING) {
    console.log('the response body is being received');
  } else if (request.readyState === 4 || 
    request.readyState === XMLHttpRequest.DONE) {
    console.log('the request is complete');
  }
};

request.open('get','http://stackoverflow.com/');
request.send();

Resources

Related Tags

129 questions
1
vote
0 answers

After Navigate2 Method returns S_OK Stuck at READYSTATE of READYSTATE_LOADING

I am working on a MFC Document View architecture application which has multiple documents and views and a tabbed window interface. I have been tasked with making an automatic switch to another tab on the press of the OK button in one of the other…
Peter Nimmo
  • 1,045
  • 2
  • 12
  • 25
1
vote
1 answer

How do I test against readystate and status in a loop to avoid the else branch ?

i have this code which is using an asynchronous AJAX object , xmlhttp xmlhttp.open(’GET’, url, true); xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState==4 && xmlhttp.status==200) { alert(xmlHttp.responseText); } …
Aaron
  • 75
  • 8
1
vote
0 answers

How to evaluate if web page has loaded?

I'm trying to make a web crawler. I want to evaluate if the web page has loaded. I tried ie.busy not working well [VBA]. It worked the first time. I changed my sub to be a function, and calling this function from a new sub I'm facing the trouble…
1
vote
1 answer

Ajax onreadystatechange function readyState

I have a script on my page that receives raw JSON data for an image back from Flickr. I want to use readyState to provide live feedback as it's taking place. What my current code is able to do is check that the readyState is 4 and the status is 200.…
Anon Omus
  • 383
  • 4
  • 12
  • 25
1
vote
1 answer

Opera HTML5 video readyState == 2 instead of equaling 4

On the 4 other main browsers (Chrome, Firefox, IE, and Safari), the readyState goes to 4 and my code executes just fine. On Opera however readyState only reaches 2 and never reaches 4. Code: var createSeekslider = function() { …
Xii
  • 13
  • 4
1
vote
0 answers

Ajax response issue in Chrome

I am working on a old piece of Ajax code which works fine with IE (i.e i am getting proper XML response) but with Chrome, I am getting null XML response (in fact responseText is also blank). When i debugged the issue with Chrome, i realized that…
Akhi
  • 11
  • 1
1
vote
1 answer

xmlhttprequest not firing response event handler for ready state 3 when using flush from php

I am sending a request a remote server from google chrom extension using xmlhttprequest I have set permissions in the manifest.json to access remote hosts Basically it is working fine as expected. what i had expected is readystate 4 it is fired when…
1
vote
3 answers

why readyState is NOT equal to 4?

I have tried to learn how to receive data from database using ajax, and i have some problem... the problem is when I submit the query I dont see any thing... i know that the problem is because the readyState is NOT equal to 4...but why? I have this…
Yossi Nagar
  • 87
  • 2
  • 10
1
vote
1 answer

vbscript internet explorer object ready state not accomplished

I apologize for my ignorance, but my fundamental understanding of scripting is quite limited to non existent. Anyway, I have to go back to the mountain for some help so here is my problem. I have a script I'm working on which will use 'for'…
Mike Bb
  • 15
  • 1
  • 4
1
vote
2 answers

Gecko WebBrowser.ReadyState

I'm creating an application that contains "geckoWebBrowser" in c #. But I have to wait the complete loading a web page, and then continue to execute other instructions. there is something similar to WebBrowser.ReadyState? thank you very much
Ldg
  • 261
  • 1
  • 8
  • 17
1
vote
2 answers

How does XMLHttpRequest know when to invoke its callback?

From what I understand, if client side javascript code uses the XMLHttpRequest to make a POST request, it waits for a response and when it completes it changes its readystate to ReadyState.Complete and invokes the callback function. My question is: …
apalopohapa
  • 4,983
  • 5
  • 27
  • 29
1
vote
1 answer

XMLHttpRequest problem

I am writing one Web Application using XUL. In that Iam using AJAX XMLHttpRequest Object for sending request to server. When I use GPRS connection to send the request to the server from my web application the request is not going, but readyState has…
A Srinivas
0
votes
2 answers

cannot reach readystate=4

I go this AJAX code that worked fine, but when I moved it to a new file it stopped working. I managed to find out that the readystate isn't 4 and status isn't 200. The code was given to my in class by the teacher. It worked find until I made new…
arthur
  • 539
  • 1
  • 7
  • 21
0
votes
1 answer

XMLHttpRequest Dosen't complete

I'm calling a PHP file with XMLHttpRequest, but now the call doesn't complete and I have no idea why. The req.readyState isn't 4, and I don't know why because the PHP file is okay and does exactly what supposed to (just echo a string). Can anyone…
eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
0
votes
1 answer

Detect when (flash) embed is ready (available)

Is it possible to detect when a Flash embed object has loaded completely? Are there events that can be subscribed to that work in all browsers?
user429620
1 2 3
8 9