Introduction:
In this article,we are going to discuss about xmlhttpobject,Xmlhttpobject properties and methods.
Main:
The XMLHttpRequest keeps alive a potentially two-way connection between the server and the browser,
which erases the biggest drawback in traditional Web applications—namely, that the connection is
closed after each call from the browser. Note that the network connects independently of the HTTP
browser request that loads the page, and can happen asynchronously (you can set the call to be asynchronous
or not, depending on how you establish the connection).
The XMLHttpRequest Object Properties,
Onreadystatechange Specifies an event handler called every time the state of the
XMLHttpRequest object changes. The valid states are enumerated for
the readyState property, shown next.
readyState Returns the state of the XMLHttpRequest object, which can have the following
values: 0=uninitialized, 1=open, 2=sent, 3=receiving, or 4=loaded.
When a complete response to the call is received, the state should equal
4, and the status (see the Status property below) should be 200.
responseText Returns the response as a string. Note that the content of the text can
possibly be well-formed XML, plain text, or JavaScript Object Notation,
or JSON (explained below). JavaScript in the browser is responsible for
parsing and making sense of the returned data.
responseXML Returns the response as XML. This property returns an XML document
object, if your application “knows” the expected structure of the
returned XML, regular expression, or string operations. A better way is
to use XML document object model (DOM) methods to extract the
objects in the data. JavaScript methods are available to parse XML.
Status Returns the numeric HTTP status (e.g., 404 for “Not Found” and
200 for “OK”)
statusText Returns the description associated with the HTTP status as a string
(e.g., “Not Found” or “OK”).
The XMLHttpRequest Object Methods
abort() Cancels the current request
getAllResponseHeaders() Returns the complete set of HTTP headers as a string
getResponseHeader(headerName) Returns the value of the specified HTTP header
open( method, URL) Specifies the method, URL, and other optional attributes of a
request.
open( method, URL, async) The method parameter can have a value of “GET”, “POST”,
or “PUT” (use “GET” when requesting data and “POST”
when sending data, especially if the length of the data is
greater than 512 bytes).
open( method, URL, async, The URL parameter may be either a relative or complete URL.
userName )
open( method, URL, async, The async parameter specifies whether the request should
userName, password) be handled asynchronously—true means that script processing
carries on after the send() method, without waiting
for a response, and false means that the script waits for a
response before continuing script processing.
send( content) Sends the request
setRequestHeader( label,
value ) Adds a label/value pair to the HTTP header to be sent
Conclusion:
Hope,this helps
Happy coding.