title: Parse JSON received with WebSocket results in error
body: <p>I have written a very simple test application that creates a websocket and parses the data it receives (server sends valid JSON data).
  The problem is that the first JSON object is parsed successfully, but all the subsequent objects are parsed with errors.</p>
  
  <p>Here's all the code:</p>
  
  <pre><code>$("#connect").click(function ()
      {
          socket = new WebSocket("my server address");
          socket.onopen = function ()
          {
              $("#log").append("Connection opened.&lt;br/&gt;");
  
              socket.send(/* login information goes here */));
          };
          socket.onerror = function (e)
          {
              $("#log").append("Error: " + e.data + "&lt;br/&gt;");
          };
          socket.onclose = function ()
          {
              $("#log").append("Connection closed.&lt;br/&gt;");
          };
          socket.onmessage = function (e)
          {
              $("#log").append(index.toString() + ": " + e.data + "&lt;br/&gt;&lt;br/&gt;");
  
              console.log("Parsing " + index);
              index++;
              var obj = JSON.parse(e.data);
              console.log("Parsed:");
              console.log(obj);
          };
      });
  </code></pre>
  
  <p>What I'm getting is: The first time "socket.onmessage" called - JSON is parsed and JS console displays an object. When second one arrives it outputs it to my "log", but JSON.parse fails with error "Uncaught SyntaxError: Unexpected token ILLEGAL".
  What is puzzling me is that the string that is received is a valid JSON object - I have tested it through several JSON validators. I have even copy-pasted it from my "log" put it in a separate file and parsed it with $.getJSON - and it worked fine, no errors.</p>
  
  <p>Browser: Chrome 13.0.782.112</p>
  
  <p>Any ideas would be helpful.</p>
  
  <p>Thank you.</p>