javascript - How to get server-send events to work -
i have html document , server-side php script trying perform server-send event with. not work -- nothing happens on page load.
html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>my title</title> <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> <!--[if lt ie 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script> function blockelasticscroll(event) { event.preventdefault() ; } </script> </head> <body ontouchmove="blockelasticscroll(event);"> <h1>my header</h1> <h2>sub-heading</h2> <div id="pool">250.00</div><div id="non-compat">sorry phone not work app.</div> <script type="text/javascript"> //check browser support if(typeof(eventsource) !== "undefined") { //create object, passing name , location of server side script var source = new eventsource('php/send_sse.php'); //detect message receipt source.onmessage = function(event) { //write received data page document.getelementbyid('pool').innerhtml = event.data; }; } else { document.getelementbyid('pool').style.display = 'none'; document.getelementbyid('non-compat').style.display = 'block'; } </script> </body> </html> php script (send_sse.php -- works when render in web browser)
<?php header('content-type: text/event-stream'); header('cache-control: no-cache'); echo "data: 500.00"; flush(); ?> some of troubleshooting
i put hook php script fire off mail message myself. received email know html doc & javascript calling php script. reason, php script not call html doc.
Comments
Post a Comment