[英]Listen to Http server-side Request (document type) Events via Javascript
I am trying to show a gif or message at the moment user click on the link or change URL to send a request to server-side (no ajax call). 我正在尝试在用户单击链接或更改URL来向服务器端发送请求(无ajax调用)时显示gif或消息。 My reason is: some pages take some seconds to be processed and it would be better user see a loading message while the request is processing.
我的原因是:一些页面需要花费几秒钟的时间来处理,最好是用户在处理请求时看到加载消息。
I tried to listen to server-side events. 我试图听服务器端事件。 I checked chrome how it works and captures this kind of requests.
我检查了chrome的工作方式并捕获了这种请求。 chrome differentiate these types of requests with others base on the document type.
chrome根据文档类型将这些请求与其他请求区分开。
My exact question is: How can I capture/listen to the HTTP request with document type via Javascript at the moment of sending the request to server? 我的确切问题是:在将请求发送到服务器时,如何通过Javascript捕获/侦听具有文档类型的HTTP请求?
I found the solution with using window.onbeforeunload() function. 我找到了使用window.onbeforeunload()函数的解决方案。 this event rise whenever any refresh or load happens.
只要刷新或加载发生,此事件就会上升。
window.onbeforeunload = function (evt) {
console.log("onbeforeunload Call listen to refresh event on _layout page.")
ShowWaiting(true);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.