Sign in
Log inSign up

onmessage in Server Side Events is not working. Can someone please help?

Alex Blattner's photo
Alex Blattner
·Feb 6, 2017

Please take a look at the following code:

function connect(){
    if(window.EventSource){
        alert(1);
        var source = new EventSource("geters/notifications.php");
        alert(2);
        source.onmessage= function(event){
            alert(3);
            if(event.data != ""){
                alert(4);
                alert(event.data);
            }
        };
    } else {
        alert("event source does not work in this browser, author a fallback technology");
    }
}

alert(3) didn't show up!

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct