How to read response headers in angularjs?

Upvote

My server returns this kind of header: Content-Range:0-10/0:

enter image description here

I tried to read this header in angular with no luck:

var promise = $http.get(url, {
    params: query
}).then(function(response) {
  console.log(response.headers());
  return response.data;
});

which just prints

Object {content-type: "application/json; charset=utf-8"}

Any ideas how to access the content range header?

Muhammad Reda

Use the headers variable in success and error callbacks

From documentation.

$http.get('/someUrl').
  success(function(data, status, headers, config) {
    // this callback will be called asynchronously
    // when the response is available
  })
  .error(function(data, status, headers, config) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

If you are on the same domain, you should be able to retrieve the response headers back. If cross-domain, you will need to add Access-Control-Expose-Headers header on the server.

Access-Control-Expose-Headers: content-type, cache, ...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to read response headers with $resource?

From Dev

AngularJS - Cannot read response headers from $http

From Dev

dart BrowserClient - how to read response headers?

From Dev

how to get headers from response in angularjs

From Dev

AngularJS - get headers in response

From Dev

How to read Token from header of a response in angularjs

From Dev

How to alter the headers of a Response?

From Dev

Cannot read response headers for CORS request with jQuery

From Dev

Read response headers from image error handler

From Dev

Read response headers from image error handler

From Dev

Access-Control-Expose-Headers Configuration for Custom Response Headers AngularJS

From Dev

angularJS cookie read response value

From Dev

How to get response headers in java

From Dev

How to modify jersey response headers

From Java

Read response headers from API response - Angular 5 + TypeScript

From Dev

how to read http headers in esb

From Dev

How to read JSON response?

From Dev

how to handle response in angularjs?

From Dev

Read response headers when using angular-spring-data-rest

From Dev

AngularJS $http object not showing all headers from response

From Dev

Cannot read response from AngularJS $resource DELETE

From Dev

AngularJS: read response data from server

From Dev

How to access response headers using $resource in Angular?

From Dev

akka-http: How to set response headers

From Dev

How to get only response headers from XMLHttpRequest

From Dev

How do you add headers to a response with a middleware?

From Dev

How to set Response Headers with Grails CacheHeaders Plugin?

From Dev

How to get response headers and body in dispatch request?

From Dev

How to access Websocket Response Headers in Javascript?

Related Related

  1. 1

    How to read response headers with $resource?

  2. 2

    AngularJS - Cannot read response headers from $http

  3. 3

    dart BrowserClient - how to read response headers?

  4. 4

    how to get headers from response in angularjs

  5. 5

    AngularJS - get headers in response

  6. 6

    How to read Token from header of a response in angularjs

  7. 7

    How to alter the headers of a Response?

  8. 8

    Cannot read response headers for CORS request with jQuery

  9. 9

    Read response headers from image error handler

  10. 10

    Read response headers from image error handler

  11. 11

    Access-Control-Expose-Headers Configuration for Custom Response Headers AngularJS

  12. 12

    angularJS cookie read response value

  13. 13

    How to get response headers in java

  14. 14

    How to modify jersey response headers

  15. 15

    Read response headers from API response - Angular 5 + TypeScript

  16. 16

    how to read http headers in esb

  17. 17

    How to read JSON response?

  18. 18

    how to handle response in angularjs?

  19. 19

    Read response headers when using angular-spring-data-rest

  20. 20

    AngularJS $http object not showing all headers from response

  21. 21

    Cannot read response from AngularJS $resource DELETE

  22. 22

    AngularJS: read response data from server

  23. 23

    How to access response headers using $resource in Angular?

  24. 24

    akka-http: How to set response headers

  25. 25

    How to get only response headers from XMLHttpRequest

  26. 26

    How do you add headers to a response with a middleware?

  27. 27

    How to set Response Headers with Grails CacheHeaders Plugin?

  28. 28

    How to get response headers and body in dispatch request?

  29. 29

    How to access Websocket Response Headers in Javascript?

HotTag

Archive