Skip to content

Commit

Permalink
Ensure we include the X-Requested-With header in requests
Browse files Browse the repository at this point in the history
The header option in a fetch call must be nested in a headers key.
  • Loading branch information
afcapel committed Jan 10, 2022
1 parent 8fead17 commit 579a033
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export default class Autocomplete extends Controller {
}

doFetch = async (url) => {
const response = await fetch(url, this.headersForFetch())
const response = await fetch(url, this.optionsForFetch())
const html = await response.text()
return html
}
Expand Down Expand Up @@ -280,8 +280,8 @@ export default class Autocomplete extends Controller {
return this.hasSelectedClass ? this.selectedClasses : ["active"]
}

headersForFetch() {
return { "X-Requested-With": "XMLHttpRequest" } // override if you need
optionsForFetch() {
return { headers: { "X-Requested-With": "XMLHttpRequest" } } // override if you need
}
}

Expand Down

0 comments on commit 579a033

Please sign in to comment.