title: Pushing updates to a webpage using server-sent events
body: <p>I would like to post data to my PHP page and then have it update the HTML page. I followed <a href="http://www.developerdrive.com/2012/03/pushing-updates-to-the-web-page-with-html5-server-sent-events/" rel="nofollow noreferrer">this</a> example of using server-sent events to push updates to a webpage.
  Here is what I have right now:</p>
  
  <p>output.html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="serverData"&gt;&lt;/div&gt;
  
  &lt;/body&gt;
  
  &lt;script type="text/javascript"&gt;
  
  //check for browser support
  if(typeof(EventSource)!=="undefined") {
      //create an object, passing it the name and location of the server side script
      var eSource = new EventSource("send_sse.php");
      //detect message receipt
      eSource.onmessage = function(event) {
          //write the received data to the page
          document.getElementById("serverData").innerHTML = event.data;
      };
  }
  else {
      document.getElementById("serverData").innerHTML="Whoops! Your browser doesn't receive server-sent events.";
  }
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>send_sse.php:</p>
  
  <pre><code>&lt;?php
  header('Content-Type: text/event-stream');
  header('Cache-Control: no-cache');
  $val = 0;
  if (isset($_POST['msg'])){
      $val = $_POST['msg'];
  }
  echo "data: $val\n\n";
  ob_flush();
  ?&gt;
  </code></pre>
  
  <p>form.html:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;form action="send_sse.php" method="post"&gt;
  Message: &lt;input type="text" name="msg"&gt;&lt;br&gt;
  &lt;input type="submit"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem is that when the form posts the value, it does not update the output.html. It does output "0" and will update whenever I manually change the value of $val and save the file. However, I want the value of $val to be determined outside of the PHP file. What am I doing wrong?</p>