Skip to content

Commit

Permalink
Add callback function to modify the XHR before sending.
Browse files Browse the repository at this point in the history
This can be used to add headers required by the api.

Fixes ivelum#6
  • Loading branch information
hterik committed Jun 20, 2023
1 parent f9cefc3 commit 39eb5c0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,21 @@ DjangoQL.prototype = {
// https://cypressnorth.com/programming/internet-explorer-aborting-ajax-requests-fixed/
/* eslint-enable max-len */
this.request.onprogress = function () {};
window.setTimeout(this.request.send.bind(this.request));

let prep;
if (this.options.prepareXhr) {
// Can be used to add extra headers
prep = this.options.prepareXhr(this.request)
}
else {
prep = Promise.resolve(this.request)
}
prep.then(() => {
window.setTimeout(this.request.send.bind(this.request));
}).catch(e => {
onLoadError()
this.logError("options.prepareXhr returned error", e)
})
},

loadIntrospections(introspections) {
Expand Down

0 comments on commit 39eb5c0

Please sign in to comment.