admin管理员组

文章数量:1315833

I'm wondering if it's yet possible to get the value of 'X-WP-Total' in the api response.

Here is my request - axios.get(${url}/wp-json/wp/v2/media?per_page=100&mime_type=image/jpeg).then(response => this.photo = response.data);

which successfully returns all the images from the media library and stores them in an object named photo.

I can see the header value of 'X-WP-Total' in Postman, and I am hoping to return that value without having to create a custom endpoint, or touch the theme file

I'm wondering if it's yet possible to get the value of 'X-WP-Total' in the api response.

Here is my request - axios.get(${url}/wp-json/wp/v2/media?per_page=100&mime_type=image/jpeg).then(response => this.photo = response.data);

which successfully returns all the images from the media library and stores them in an object named photo.

I can see the header value of 'X-WP-Total' in Postman, and I am hoping to return that value without having to create a custom endpoint, or touch the theme file

Share Improve this question asked Jun 2, 2019 at 14:01 ElouiseElouise 11 silver badge1 bronze badge 1
  • If you can see those headers in postman then Axios will be getting them too, you just need to inspect the response object to see where Axios stores response headers – Tom J Nowell Commented Nov 17, 2020 at 12:30
Add a comment  | 

1 Answer 1

Reset to default 1

Ideally, you can access those headers with response.header, but not all headers are available publicly unless exposed manually. In your case, to access X-WP-Total by the client, you need to set the Access-Control-Expose-Headers header on your server:

Access-Control-Expose-Headers: X-WP-Total

本文标签: javascriptReturn 39XWPTotal39 from headers in response