Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read xhr.getResponseHeader? #801

Closed
uaibo opened this issue Jun 2, 2018 · 2 comments
Closed

How to read xhr.getResponseHeader? #801

uaibo opened this issue Jun 2, 2018 · 2 comments

Comments

@uaibo
Copy link

uaibo commented Jun 2, 2018

Here is a demo for my issue: http://jsbin.com/jepifofaha/edit?js,output (put it there because CodePen was giving me errors and was blocking the requests)
As you can notice after two requests, the page limit is reached and the API returns empty result but the InfiniteScroll isn't able to detect that and keeps sending requests infinitely.

_

An even bigger problem is when I use a Wordpress REST api endpoint (which I can't demonstrate here now), where when pagination exceeds total pages count, the request returns a HTTP 400 error which then blocks all my orher scripts and nothing else works after that.

_

Usually all these api endpoints return total pages count in the response header. The above demo returns "X_TOTAL_COUNT" in response header from which I can calculate total pages available and stop making new requests after pagination exceeds total pages available.

I'm pulling my hair out since yesterday and can't find a way to read response headers (you know basically XHR variable)

Any help or suggestion? Is it possible? Can you suggest any workaround?

@desandro
Copy link
Member

desandro commented Jun 2, 2018

I'm sorry to say that Infinite Scroll does not currently provide an API for the XMLHttpRequest object using in request.

Add a 👍 reaction to this issue if you would like to see this feature added. Do not add +1 comments — They will be deleted.

@desandro
Copy link
Member

Infinite Scroll v4 has been released. Infinite Scroll v4 adds a new option, fetchOptions, which allows you to set method, headers, CORS mode, and other options for the fetch request

fetchOptions: {
  mode: 'cors',
  cache: 'no-cache',
  credentials: 'same-origin',
  headers: {
    'X-Session-Id': '33vscths658h7996d324rqft1s',
  },
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants