html5 - servlet Server-sent event not working with Chrome/Safari -


i working on servlet encountered problem. sse works fine firefox cannot work chrome/safari. similar code in php can run smoothly in 3 browsers mentioned above. how solve problem? thx!!

this servlet code:

    response.setcontenttype("text/event-stream;charset=utf-8");     response.addheader("cache-control", "no-cache");     printwriter out = response.getwriter();     out.print("data: " + new date());     out.flush();     out.close(); 

and js code:

           if (typeof(eventsource) !== "undefined")         {             var source = new eventsource("sse");             source.onmessage = function(event)             {                 document.getelementbyid("result").innerhtml += event.data + "<br />";                 alert("ok");             };         }         else         {             document.getelementbyid("result").innerhtml = "sorry, browser not support server-sent events...";         } 

btw, using glassfish.

you may want modify line out.print("data: " + new date()); out.print("data: " + new date() + " \n\n"); browser gets stuck finding no double "\n" @ end of sse data message.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -