shashib Posted August 6, 2014 Share Posted August 6, 2014 Hi i am using HTML5 Server-Sent Events Actually i need to show notification ( new record enter and which are unread ) thats when any new record is insert in database ( php / mysql ) So for testing purpose i just tried with count of total row. but getting below error message in my localhost : Firefox can't establish a connection to the server at http://localhost/project/folder/servevent/demo_sse.php.line is : var source = new EventSource("demo_sse.php"); WHAT I HAVE TRIED : index.php <script>if(typeof(EventSource) !== "undefined") {var source = new EventSource("demo_sse.php");source.onmessage = function(event) {document.getElementById("result").innerHTML = event.data;};} else {document.getElementById("result").innerHTML = "Sorry, your browser does not support server-sent events...";}</script> <div id="result"></div> demo_sse.php <?phpheader('Content-Type: text/event-stream');header('Cache-Control: no-cache');$db = mysql_connect("localhost", "root", ""); // your host, user, passwordif(!$db) { echo mysql_error(); }$select_db = mysql_select_db("testdatase"); // database nameif(!$select_db) { echo mysql_error(); }$time = " SELECT count( id ) AS ct FROM `product` ";$result = mysql_query($time);$resa = mysql_fetch_assoc($result);echo $resa['ct'];flush();?> please let me know what going wrong. I know for notification we can use Ajax with some interval time , but i don't want such thing. As i have N number of records and which may slow my resources. Link to comment Share on other sites More sharing options...
thescientist Posted August 6, 2014 Share Posted August 6, 2014 are checking for Apache error logs? can you hit the PHP file itself directly in the browser? Link to comment Share on other sites More sharing options...
shashib Posted August 7, 2014 Author Share Posted August 7, 2014 (edited) yes i can hit php file directly and getting result too .. but @ index.php the outcome is not seen ..also error is in firebug Edited August 7, 2014 by shashib Link to comment Share on other sites More sharing options...
shashib Posted August 7, 2014 Author Share Posted August 7, 2014 any master here ? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 7, 2014 Share Posted August 7, 2014 Like the example you linked to shows, maybe the problem is that your output does not start with "data:". Link to comment Share on other sites More sharing options...
shashib Posted August 12, 2014 Author Share Posted August 12, 2014 please can you brief with example Link to comment Share on other sites More sharing options...
justsomeguy Posted August 12, 2014 Share Posted August 12, 2014 There's an example on the page you linked to in the first post. Note that the response starts with "data:", and the note below tells you that every response should start with that. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now