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

C# - Automatic Login to a webpage using WebBrowser - disabled html tag

After some research on the WebBrowser DocumentCompleted issue, I've inserted my login attempt into the DocumentCompleted Event Handler. Here's my code: public void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { …
Maayan
  • 208
  • 2
  • 7
0
votes
1 answer

ajax httprequest time / no multiple requests

What i'm working on is a chat, so i want a database read/display every 1 second and also by submitting a new message. I figured my httprequest doesn't work (doesn't get past readystate 1) because i trigger a new request while an old one isn't…
br4nnigan
  • 646
  • 6
  • 13
0
votes
1 answer

xmlhttp.readyState not working with mysql transaction

i have an ajax function where i am simply calling a php page which has a mysql transaction to be run. On checking mysql log, i have verified that the transaction runs successfully but xmlhttp object jumps to the else statement readyState and…
coder101
  • 1,601
  • 2
  • 21
  • 41
0
votes
1 answer

ajax XMLHttpRequest readystate

I have an html page with this form
0
votes
1 answer

xml onreadystatechange issues

I'm trying to work my way out with XMLHttpRequest, but I've run into an issue: function x(url, callback) { //edited xmlHttp.onreadystatechange = function() { if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 ) { …
Alex
  • 7,538
  • 23
  • 84
  • 152
0
votes
1 answer

Gecko WebBrowser.DocumentComplete Event

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 geckowebbrowser1.DocumentComplete, but i don't…
Jonas Gobel
  • 153
  • 3
  • 5
  • 13
-1
votes
1 answer

Remove a tablerow in an Ajax callback, but Ajax won't get past readyState 1

I'm trying to remove a tablerow. It seems that it only gets to readyState 1 Here it is: var element = $('table:nth-child(5)>tbody>tr:nth-child(5)'); $.ajax({ success: function(){ element.remove(); } });
gotex
  • 1
  • 2
-1
votes
1 answer

Document.readystate is lying about Google Maps canvas images being loaded

I am printing a page containing google maps API v3 map from within an iframe. I implemented the following code to make sure the page has loaded fully before printing the iframe. /** * Auto print the page once the full document has finished…
TetraDev
  • 16,074
  • 6
  • 60
  • 61
-1
votes
3 answers

jQuery ajax return elements can't be selected

I'm having an issue with ajax generated selectors. basically i have a start button in default state. onclick, it starts something, and then the click also brings in a new div from an ajax call with results. one of these items is the stop…
BReal14
  • 1,603
  • 1
  • 12
  • 35
1 2 3
8
9