XML-HTTP Request interview questions
XML-HTTP Request - August 29, 2008 at 17:10 pm by Amit Satpute
What is the XMLHttpRequest Object?
The XMLHttpRequest object is used to connect to the server through http.
Scripts use it to do so programmatically.
The EventTarget interface needs to be implemented if an object implements the
XMLHttpRequest interface. Also, an XMLHttpRequest() constructor needs to be
provided by objects that implement the Window interface.
Explain common XMLHttpRequest Object Properties. i.e. onreadystatechange,
readyState, responseText, responseXML, status, statusText.
-
The ‘onreadystatechange’ property fires at every state change event.
-
The ‘readyState’ property is an object status integer. It uses the integers 0
to 4 for uninitialized, loading, loaded, interactive and complete states.
-
The ‘responseText’ property is a string version of data returned from server
process.
-
The ‘responseXML’ property is DOM-compatible document object of data returned
from server process.
-
The ‘status’ property is for returning numeric codes from the server like error
codes, etc.
-
The ‘statusText’ property is used for string messages that accompany the status
code.
Explain common XMLHttpRequest Object Methods.
-
The abort() is used to stop the current request.
-
The getAllResponseHeaders() method is used to return the full set of headers as
a string.
-
The getResponseHeader("headerLabel") method is used to return the string value
of a single header label.
-
The open("method", "URL"[, asyncFlag[, "userName"[, "password"]]]) is used to
assign the destination URL, method, and other optional attributes of a request.
-
The send(content) method transmits the request, optionally with postable string
or the data of DOM object.
-
The setRequestHeader("label", "value") method is used to assign a label/value
pair to the header to be sent with a request.
|