接收服务器发送的事件通知

时间:2019-06-20 22:22:50

标签: javascript vbscript asp-classic

我有这个服务器从w3schools发送事件的示例。 .php代码可以正常工作。但是,我需要.asp版本,该示例不起作用。我没有从服务器端脚本得到任何响应。有帮助吗?

     <!-----------Client side-------------->

     <!DOCTYPE html>
     <html>
     <body>

      <h1>Getting server updates</h1>
      <div id="result"></div>

      <script>
      if(typeof(EventSource) !== "undefined") {
      var source = new EventSource("demo_sse.asp");
      source.onmessage = function(event) {
      document.getElementById("result").innerHTML += event.data + "<br>";
      };
      } else {
      document.getElementById("result").innerHTML = "Sorry, your browser does not support server-sent events...";
     }
     </script>

     </body>
     </html>

     <!---------------Server side--------------->

     <%
     Response.ContentType = "text/event-stream"
     Response.Expires = -1
     Response.Write("data: The server time is: " & now())
     Response.Flush()
     %>

1 个答案:

答案 0 :(得分:0)

您可能不相信这一点,但是...请尝试以下行:

Response.Write("data: The server time is: " & now()) & vbCrLf & vbCrLf

这对我有用! See this answer - the last one