You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have had a look at the source for ampersand-sync and xhr, and it seems that ultimately when beforeSendis called in xhr, no control over when the request is actually sent is ceded to it.
I suspect this is something that is related to the xhr module, rather than ampersand-sync, but I wonder if anybody has encountered this before.
My specific use case is that occasionally I need to fetch a new access token from an API before a request is made. If either ajaxConfig or beforeSend waited for a callback to continue, I could first fetch my access token, set it for the pending request and continue.
The text was updated successfully, but these errors were encountered:
Hi, I'm one of the maintainers of xhr and recently a contributor here.
beforeSend is available in ampersand-sync mostly as a legacy from backbone/jQuery.ajax and the original one is also synchronous. I'm pretty sure that for the sake of adoption etc. it'd be better if we didn't start requiring it to call a callback when done. (for the same reason I would consider aborting on return false naugtur/xhr#83)
It's been a while and you probably found a workaround. Would you like to share?
It could probably be hacked like this (not tested):
beforeSend: function(xhr){varorigSend=xhr.send;xhr.send=function(body){//do async magic, and then call:origSend.call(xhr,body)}}
My workaround is very inelegant; it involves occasionally requesting a new access token while the client has a valid refresh token. The logic to do this in an offline available single page app with many forms was quite horrible!
Switching to this solution will eliminate a bunch of code and hoops to jump through. Thanks for for the help, it is much appreciated! 😊
I have had a look at the source for ampersand-sync and xhr, and it seems that ultimately when
beforeSend
is called in xhr, no control over when the request is actually sent is ceded to it.I suspect this is something that is related to the xhr module, rather than ampersand-sync, but I wonder if anybody has encountered this before.
My specific use case is that occasionally I need to fetch a new access token from an API before a request is made. If either
ajaxConfig
orbeforeSend
waited for a callback to continue, I could first fetch my access token, set it for the pending request and continue.The text was updated successfully, but these errors were encountered: