metafizzy / infinite-scroll

📜 Automatically add next page
https://infinite-scroll.com
7.41k stars 1.74k forks source link

Add headers option #917

Closed solisoft closed 3 years ago

solisoft commented 4 years ago

This PR allow a user to set extra headers on each requests using the headers options

Here a usage

$('.videos').infiniteScroll({
    append: false,
    history: false,
    responseType: 'text',
    headers: function () {
      return [['X-Session-Id', localStorage.getItem('X-SessionFront-Id')]]
    },
    path: function() {
      self.current_page = this.loadCount + 2
      if( self.current_page <= count ) {
        return path + self.current_page
      }
      self.update()
    },
    status: '.scroll-status',
})
desandro commented 3 years ago

Thank you for this contribution! This looks straightforward. I may re-tool this a bit.

Related #791

desandro commented 3 years ago

Infinite Scroll v4 has been released. Infinite Scroll v4 adds a new option, fetchOptions, which allows you to set headers and other fetch options.

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

Thank you for your original contribution. While I did not merge it in, your effort did help me decide to support the feature.