Jump to content
Sign in to follow this  
shashib

Firefox can't establish a connection to the server - Server Sent Events

Recommended Posts

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.

 

Share this post


Link to post
Share on other sites

are checking for Apache error logs? can you hit the PHP file itself directly in the browser?

Share this post


Link to post
Share on other sites

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 by shashib

Share this post


Link to post
Share on other sites

Like the example you linked to shows, maybe the problem is that your output does not start with "data:".

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...