我有这个服务器从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()
%>
答案 0 :(得分:0)
您可能不相信这一点,但是...请尝试以下行:
Response.Write("data: The server time is: " & now()) & vbCrLf & vbCrLf