I made a ASP script with all headers necessary for Server Sent Events. The client side script is working. I tested it with a PHP script and it works fine. The ASP script works and it returns the expected message if you call it from the URL line, but when the javascript calls it, the element inspector returns the data as "undefined". When I set the breakpoint to the "open" event listener, the "e.data" is "undefined".
For some reason Javascript is not accepting the UTF-8 text sent by the ASP script.
Help me please!!!
The asp code:
strResponse = strResponse & "data: " & now()
response.Buffer = true
response.CharSet = "utf-8"
response.ContentType="text/event-stream"
response.AddHeader "content-Type", "text/event-stream;charset=UTF-8"
response.AddHeader "Cache-Control", "no-cache"
response.AddHeader "Content-Length", len(strResponse)
response.AddHeader "Connection", "Keep-Alive"
response.Write strResponse
The Javascript:
if (!!window.EventSource) {
var source = new EventSource('serversend.asp');
source.addEventListener('message', function (e) {
console.log(e.data);
}, false);
source.addEventListener('open', function (e) {
console.log("open " + e.data);
}, false);
source.addEventListener('error', function (e) {
if (e.readyState == EventSource.CLOSED) {
console.log(e.data);
}
}, false);
} else {
// something else :(
}
Thank you!
Try This Is Working
Response.Flush()
Try to use
Response.Flush
afterResponse.Write
Edit* Put two enters after the strResponse string:
response.Write strResponse & vbCrLf & vbCrLf