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
1 answer

MSXML ASP Classic feed page - timing out and ReadyState stuck on 1

I'm currently working on a page in Classic ASP (VB) which utilizes MSXML to read an external XML feed. While this is working with no problem (ReadyState 4 reached) in localhost on my pc, once the code is on the server, it times out, with this…
buck1112
  • 504
  • 8
  • 24
0
votes
1 answer

Ajax keeps site on the Loading

I ve been trying to figure out how to make this work. var request; if(window.XMLHttpRequest){ request= new XMLHttpRequest(); }else{ request = new ActiveXObject("Microsoft.XMLHTTP"); } var handleStateChange = function () { switch…
Metalbreath
  • 119
  • 1
  • 14
0
votes
0 answers

How to detect that document's content is loaded?

I want to detect when a document has finished loading all its content. The document is coming from Main doc's first frame i.e var frameList = window.top.document.getElementsByTagName("iframe"); if(frameList.length == 0) { frameList =…
SHASHA
  • 90
  • 1
  • 12
0
votes
1 answer

Check ReadyState in GeckoFX

I use WebBrowser control for my C# project. I try to integrate GeckoFX instead of WebBrowser. Because i always change inputs in WebBrowser, i have to wait till the website loaded completely. That's why, i use following method: private void…
naex
  • 21
  • 6
0
votes
1 answer

Why does InternetExplorer Object become unresponsive?

I am attempting to login to a password protected site. I'm using the InternetExplorer Object in VBScript. Error lies after oIE.readystate value is read one time - that is, in my loop, it reads the oIE.readystate value one time, but upon the second…
nezam
  • 1
  • 1
0
votes
2 answers

readyState always 1 and status is undefined

Can anyone please tell me why I am getting readyState as 1 and status as undefined for the following $(document).ready(function(){ $('.delsub').on('submit', function (event){ event.preventDefault(); var xhr = $.ajax({ …
Sajin
  • 57
  • 1
  • 10
0
votes
1 answer

jQuery Ajax readystate 0 status 0 in Windows 8 (8.1) on Chrome ONLY

I have this bit of jQuery doing an ajax call. The script was having issues in IE and Chrome on Win 8.1 only, however, i changed a few things (including ommitting a closing php tag that might have been causing issues) and now IE works and on my…
Tech Savant
  • 3,686
  • 1
  • 19
  • 39
0
votes
2 answers

Problem with Ajax submission?

I am using Ajax to post data to the server(PHP code) and update it. i am posting many data one after the other, but in between the Ajax post fails and dont return a readyState to 4. the code is as follows function getHttpRequest() { var…
Harish Kurup
  • 7,257
  • 19
  • 65
  • 94
0
votes
1 answer

changing state of document.readyState to "complete" after downloading file via PHP's header('Content-Disposition: attachment...'

My question is this: after downloading a file via PHP's header('Content-Disposition: attachment... technique, the webpage that originated the download has a document.readyState value of interactive. I would expect this to be complete instead, as…
yybtcbk
  • 3
  • 3
0
votes
0 answers

createElement: How to make this cross-browser - works in IE10

I have the following javascript which is a loader that is triggered and created when the page is idle. It basically shows whilst the next navigated page is loading. The script resides on the (ASP.NET) master page and an Ajaxified user control. I…
0
votes
1 answer

IE Readystate stuck at 1 during VBA webscraping

When attempting to reach a URL my code gets stuck in my readystate loop and never loads. The readystate remains at 1 permanently. If I pause the code and hit debug the cursor skips around my procedure in a bizarre order, sometimes to the end then to…
Mike
  • 43
  • 2
  • 11
0
votes
2 answers

readyState will not change to 4

I am trying to create a dynamic AJAX search bar which communicates with my database. Here is my code. function getXmlHttpRequestObject(){ if(window.XMLHttpRequest){ return new XMLHttpRequest(); } else if (window.ActiveXObject){ return new…
Adam Piper
  • 505
  • 1
  • 5
  • 11
0
votes
1 answer

Check if window dom is parsing or not

So SDK has this function that checks if window is loading, the code for that is below. My question is what if an innerHTML or appendChild or something to change html happens? Does that bring back loadContext? I want to know if the DOM in a window is…
Noitidart
  • 35,443
  • 37
  • 154
  • 323
0
votes
1 answer

HTML5 video, waiting for video end, waiting for video ready

Hello as you can see from my sample code i am trying to play an array of videos back to back. What i attempt to do is create a for loop which cycles for the length of the array. Within the for loop i call a PlayAVideo function that empties a div…
hfrog713
  • 400
  • 1
  • 5
  • 18
0
votes
1 answer

Ajax code with readState and status property

This is my first code in ajax.......please can anybody help me out....the readySTate and status property is never getting true....it shows xhrobj.readyState=1 and xhrobj.status=0..?? MISCELLANEOUS QUESTION NO.1
Steve
  • 522
  • 3
  • 12
  • 28
1 2 3
8
9