I am working on AngularJS 1.6 version. In my app.controller.js I have added three event listeners and attached a deleteStudent method.
window.addEventListener('beforeunload', this.deleteStudent, false);
window.addEventListener(
'unload',
() => {
this.deleteStudent
},
false
);
window.addEventListener('pagehide', this.deleteStudent, false);
deleteStudent() {
let Url = "http://localhost:9000/students/3";
const deleteMethod = {
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
},
keepalive: true
};
fetch(Url, deleteMethod);
}
The API call is not reaching backend but getting listed on the chrome network tab as pending state.
*The above used delete API is created in Node js and working fine with postman.
I have to call this API at the time of page unload only, where it is recommended to use either fetch API with keep-alive property true or use sendBeacon(), but my backend API is of type DELETE therefore I can not use sendBeacon() as it only supports POST.