XMLHttpRequest Object Methods And Properties
getAllResponseHeaders() Method
Return all the response header in the form of single string.
getAllResponseHeaders();
Example of getAllResponseHeaders
function loadXMLDoc() { var xmlhttp; var url="index.html"; if (window.XMLHttpRequest) xmlobj=new XMLHttpRequest(); else xmlobj=new ActiveXObject("Microsoft.XMLHTTP"); xmlobj.onreadystatechange=function() { if (xmlobj.readyState==4 && xmlobj.status==200) { document.getElementById('uk').innerHTML=xmlobj. getAllResponseHeaders(); } } xmlobj.open("GET",demo.txt,true); xmlobj.send(); }
getResponseHeader() Method
Return all the response header in the form of single string.
getResponseHeader(name-of-header);
Example of getResponseHeader
getResponseHeader('Last-Modified');
abort() Method
Abort function is used to stop the current request.
abort();
Example of abort function
xmlobj.abort();
open(method, url, async, uname, pswd) Method
Specifies the HTTP method to be used GET or POST as a string, the target URL and whether or not the request should be handled asynchronous. (asyn should be true or false , omitted true is assumed)
Note: method, url, async are the required parameter and uname, pswd are the optional parameter.
xmlobj.open("GET",url,true);
Example of open method
xmlobj.open("GET","demo.txt",true);
send() Method
Send the data for a POST request and status the request, if GET Method is used, you should call send(Null) string is used for post request only.
xmlobj.send();
Example of send method
xmlobj.send();
setRequestHeader() Method
Set a parameter and value pair like x=y and assign it to the header to be sent with the request.
setRequestHeader("key", "value");
Example of setRequestHeader
xmlobj.setRequestHeader("Cache-Control", "no-cache");