I am using Fetch API in my angular JS app to run a service right before the user closes the browser. What this service does is to free up a record which was locked by a user and which remained unlocked because user accidentally closed the browser. The fetch method runs just fine and it unlocks the record when I test it locally. However it doesn't work for me when I test it on the server after deployment. Also it works for some of the my teammates and doesn't work for some on the same server. The following is the method which I am calling on page unload.
var runService = function (id) {
var url = '/service/to/run/' + id;
return window.fetch(url, {
method: 'POST',
keepAlive: true,
headers: {
'Authorization': 'Bearer token' + getSessionValue('access_token')
}
});
}
I have tried for days now, to make it work by adding/removing parameters, but still no success. I tried to use sendBeacon
, but that doesn't work either. I am writing this question after all the efforts that I could do. I would be very grateful if anyone can point me to the right direction.