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
0
votes
2 answers

Is there a better way to accomplish this loop?

I'm pretty new with VBA, but I've been muddling through to make a program for my team. This piece of code works most of the time, but tends to hang on occasion. I can't figure out why it would hang sometimes, and work perfectly most of the time, so…
dualpoodle
  • 15
  • 4
0
votes
0 answers

Converting XMLHttpRequest responseText to a variable and running if logic in readystate

I've been trying to solve a coding issue for some days now. I can't figure out how this asynchronous coding works despite reading several posts. Hopefully someone on here can point me in the correct direction. Below is what I'm trying to achieve,…
EPV77
  • 1
0
votes
1 answer

Equivalent of readystatechange after changing page content using javascript

I am modifying dynamically a part of page (which is loaded only once), using javascript. I am looking for an equivalent of readystatechange event that will be triggered when all images, fonts, ... are loaded after the partial page change. How can I…
AP.
  • 5,205
  • 7
  • 50
  • 94
0
votes
0 answers

How to access IE object's ReadyState in a VB application?

I'm creating a small application in VB.NET that opens a URL using an 'invisible' instance of Internet Explorer and I need to monitor the progress of the page as it loads in the background and then parse its contents. I have the follow code working…
my MDB
  • 129
  • 1
  • 2
  • 10
0
votes
1 answer

ReadyState interactive vs DOMContentLoaded

I was setting up a very simple page to populate a dropdown list from an array on DOMContentLoaded Event, however in my environment (VS code + live Server extension), I was getting an error because the entire body object didn't exist at the moment…
0
votes
1 answer

Javascript inserting html between readyState loading and complete

I'm looking for a way to insert html (tags) into a website at a specific location as early as possible. The insertion it self is not an issue, I'm merely looking for a way to speed it up by not needing to wait for the readyState complete to fire. I…
user2693017
  • 1,750
  • 6
  • 24
  • 50
0
votes
1 answer

Wait until page is fully loaded using InternetExplorer Object from SHDocVw in C#?

How can the code wait until the webpage is fully loaded using the InternetExplorer Object from SHDocVw. in C#??? thank you very much My code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using…
Weichafe
  • 97
  • 1
  • 10
0
votes
2 answers

how to know iframe is ready for... using jquery

i am using jquery extruder menu (http://pupunzi.com/#mb.components/mb.extruder/extruder.html). That menu has callback functions on open/close. I am trying to show/hide a div inside the iframe using that callback functions for a particular page only,…
rajaishbt
  • 210
  • 1
  • 5
  • 13
0
votes
2 answers

Javascript: xmlhttprequest randomly stuck at Ready State 1

I've been working on a Windows gadget (meaning the "browser" is Internet Explorer) that queries specified subnet addresses for information. Now, it sometimes does this at a relatively quick pace (roughly every 5 seconds) and it works well enough. …
user535617
  • 634
  • 2
  • 7
  • 22
0
votes
1 answer

vb6: click button on HTMLDocument by code and wait for page to be loaded

i'm using the mshtml.tlb for loading/parsing html and i'd like extend it for clicking elements by code. the problem is trapping the loading-process after eg. a button was clicked. in my specific case i'd like to perform a user-login. here's my…
Fuxi
  • 7,611
  • 25
  • 93
  • 139
0
votes
1 answer

XMLHttpRequest Level 2 events: equivlents to readyState

XMLHttpRequest Level 2 adds a number of more meaningful events over the onreadystatechange one. Is there a correspondence between some of these events and the readyState values? As far as I can tell: 1 loadstart 2 progress 3 ? 4 loadend;…
Manngo
  • 14,066
  • 10
  • 88
  • 110
0
votes
2 answers

Json file wont load in with jquery .getJSON()

I'm trying to assign a external json file to a var with jquery's getJSON(). In my JSON file i have the same exact code as for outp. when I try to console.log what is in the data var, it only show's readyState1. That means that I'm connected with the…
Niqql
  • 410
  • 1
  • 5
  • 26
0
votes
1 answer

AJAX request doesn't work the first time but works thereafter

I'm making a simple function as it is shown on w3schools official website. I'm trying to run a function of an AJAX request. I guess it's all working well except the fact that the code ONLY runs after it fails the first time. I mean, let's say you…
joaogeraldes
  • 15
  • 1
  • 6
0
votes
1 answer

HTML5 Video readyState with Event Listener

Trying to display a 'loading' div until my MP4 is done buffering. Seems like it should do the trick, but no go- loading stays up even when done buffering! Any suggestions?
0
votes
1 answer

Operation Systems: How process move from device' queue(waiting) to ready queue?

When a process in currently running in the cpu and suddenly have to wait for I\O, then the scheduler save its state (Program counter, registers..) into is PCB, and then add him to the device queue which the process wait for I\O from it. when the…
1 2 3
8 9