lanzx3finalz Posted June 29, 2013 Share Posted June 29, 2013 Can any one help me create a mysql server notification everytime my mysql update or has a new data it will show in the website using HTML5 Receive Server-Sent Event Notifications Heres my code: /////////////////noti.php <!DOCTYPE html> <html> <body> <title>Notification</title> <div id="result"></div> <?phpinclude 'connect.php';?> <script> if(typeof(EventSource)!=="undefined") { var source=new EventSource("demo_sse.php"); source.onmessage=function(event) { document.getElementById("result").innerHTML+=event.data + "<br>"; }; } else { document.getElementById("result").innerHTML="Sorry, your browser does not support server-sent events..."; } </script> </body> </html> /////////////demo_sse.php <?php include 'connect.php'; header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); $data = mysql_query("SELECT * FROM contact") or die(mysql_error()); while($row = mysql_fetch_array( $data )) { echo '' . $row['name'] . ''; } echo "{$data}nn"; flush(); ?> Link to comment Share on other sites More sharing options...
Ingolme Posted June 29, 2013 Share Posted June 29, 2013 You haven't defined EventSource() in this line: var source=new EventSource("demo_sse.php"); 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