XMLHttpRequest (XHR) objects is a core of Ajax used to interact with servers. This helps you to retrieve data from a URL without having to do a full page refresh. This enables a Web page to update just part of a page without reloading the whole page.
Note: Despite its name,
XMLHttpRequest can be used to retrieve any type of data, not just XML.
In the following example, we request a URL and receive a response.
|abort()||Terminate the current request.|
|getAllResponseHeaders()||Returns all the response headers|
|getResponseHeader()||Returns the string containing the text of a particular header's value.|
|new XMLHttpRequest()||Creates a new XMLHttpRequest.|
|open(method,url,async,user,pass)||Initializes a newly-created request, or re-initializes an existing one.|
|send(data)||sends the request to the server.|
|setRequestHeader()||Sets the value of an HTTP request header.|
|onreadystatechange||Specifies a function which is called from the user interface thread.|
|readyState||Returns the state an XMLHttpRequest client is in.|
Possible values are
|responseText||Returns the text received from a server following a request being sent.|
|responseXML||Returns a Document containing the HTML or XML retrieved by the request.|
|status||Returns the numerical HTTP status code of the XMLHttpRequest's response.|
|statusText||Returns a DOMString containing the response's status message as returned by the HTTP server.|
For security reasons, browsers do not allow access across domains.
For example: From www.abc.com you can't send XMLHttpRequest to www.xyz.com.
All resources of www.abc.com can only be accessed by itself.
This channel is primarily useful for Full Stack Web Developer.