How does js monitor window closing events, and why do I not execute ajax like this?

  node.js, question

Now I need to monitor whether the window is closed or not. If it is closed, I need to send a request to the background. But why can’t I execute ajax? Which great god can help me?

You’re right upstairs. It’s unrealistic for you to perform asynchronous AJAX operations when closing the web page. The browser will abort this request when closing the web page. The background will probably not receive the request.