You are here: Reference > JavaScript > client-side > xml handling > methods > getAllResponseHeaders (XMLHttpRequest)

getAllResponseHeaders method (XMLHttpRequest)

Browser support:
Returns a string that contains all response headers.
The response headers contain information about the server and the retrieved content ('Content-Length', 'Content-Type', ...). To get the value of a specific response header, use the getResponseHeader method.


object.getAllResponseHeaders ( );
You can find the related objects in the Supported by objects section below.

Return value:

String that contains name/value pairs delimited by new line characters.

Example HTML code 1:

This example illustrates the use of the getAllResponseHeaders method:
    <script type="text/javascript" src="ajax.js"></script>
    <script type="text/javascript">
        var httpRequest = null;

        function SendRequest () {
            if (!httpRequest) {
                httpRequest = CreateHTTPRequestObject ();   // defined in ajax.js
            if (httpRequest) {          
                    // The requested file must be in the same domain that the page is served from.
                var url = "news.xml";
       ("GET", url, true);    // async
                httpRequest.onreadystatechange = OnStateChange;
                httpRequest.send (null);

        function OnStateChange () {
            if (httpRequest.readyState == 0 || httpRequest.readyState == 4) {
                if (IsRequestSuccessful (httpRequest)) {    // defined in ajax.js
                    Test_ResponseHeaders ();
                else {
                    alert ("Operation failed.");

        function Test_ResponseHeaders () {
            if (httpRequest.getAllResponseHeaders) {
                var headers = httpRequest.getAllResponseHeaders ();
                alert (headers);
            else {
                alert ("Your browser doesn't support getAllResponseHeaders method");
    <button onclick="SendRequest ()">Test response headers</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content