hook for modifying XHR before JSON feed request
See original GitHub issueHello,
I’m trying today to migrate my company’s app from v3 to v4, and I’m facing a problem with eventSources component. In v3, we used beforeSend
function to get http request, and set Authorization header (for bearer token).
Now in v4, it does not call beforeSend
function, and does not use headers
params. I didn’t find any doc or code from the internet with a solution.
Is it just not implemented ?
We’ve search in source and found nothing about it too.
What I tried :
(v3 base code)
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
},
(v4)
headers: { 'Authorization': 'Bearer ' + token }
headers: { Authorization: 'Bearer ' + token }
Thanks in advance !
Issue Analytics
- State:
- Created 4 years ago
- Reactions:21
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Is it possible to modify XMLHttpRequest data from beforeSend ...
Yes you can modify it, the signature of beforeSend is actually (in jQuery 1.4+): beforeSend(XMLHttpRequest, settings).
Read more >XMLHttpRequest - Web APIs - MDN Web Docs
Chrome Edge
XMLHttpRequest Full support. Chrome1. Toggle history Full support. Edge12...
XMLHttpRequest() constructor Full support. Chrome1. Toggle history Full support. Edge12...
abort Full support. Chrome1. Toggle...
Read more >jQuery.ajax() | jQuery API Documentation
A pre-request callback function that can be used to modify the jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object before it is sent.
Read more >jQuery AJAX POST Tutorial - AirPair
Just as the HTML page from our mental model above was a single GET request, we could do the same with other types...
Read more >Data Fetching Techniques with React - OpenReplay Blog
We will focus on using Hooks introduced in React 16.8 to fetch data from the popular JSON Placeholder API to be displayed in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t know if you’ve solved your problem @azuken, but I found a solution in the event source as a function.
I also used the same approach for the resources, which works for me. It’s not the most elegant way, but it gets the job done.
Anyhow, just thought I’d share my solution.
in v4, we should offer a hook to manipulate the XHR before it requests. keeping this ticket open for this feature request