title: SyntaxError: expected expression, got ')'
body: <p>I've been stuck at this error for a few days and still couldn't figure out what is wrong. Would be great if someone could just point me to the right direction of solving this issue.</p>
  
  <p><strong>Update:</strong>
  I realise that error is gone when I commented "addMessages(xml)" in the updateMsg() function. How do I make it work then?</p>
  
  <p><strong>Error:</strong>
  <a href="http://i.imgur.com/91HGTpl.png" rel="nofollow">http://i.imgur.com/91HGTpl.png</a></p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>$(document).ready(function () {
      var msg = $("#msg");
      var log = $("#log");
      var timestamp = 0;
  
      $("#name").focus();
  
      $("#login").click(function() {
          var name = $("#name").val();
          if (!name) {
              alert("Please enter a name!");
              return false;
          }
  
          var username = new RegExp('^[0-9a-zA-Z]+$');
  
          if (!username.test(name)){
              alert("Invalid user name! \n Please do not use the following characters \n `~!@#$^&amp;*()=|{}':;',\\[\\].&lt;&gt;/?~@#");
              return false;
          }
  
          $.ajax({
              url: 'login.php',
              type: 'POST',
              dataType: 'json',
              data: {name: name},
              success: function() {
                  $(".login").hide();
              }
          })
          return false;
      });
  
      $("#form").submit(function() {
          if (!msg.val()) {
              return false;
          }
  
          $.ajax({
              url: 'add_message.php',
              type: 'POST',
              dataType: 'json',
              data: {message: msg.val()},
          })
  
          msg.val("");
  
          return false
  
      });
  
      window.setInterval(function () {
          updateMsg();
      }, 300);
  
      function updateMsg() {
          $.post('server.php', {datasize: '1024'}, function(xml) {
              addMessages(xml);
          });
      }
  
      function addMessages(xml) {
  
          var json = eval('('+xml+')');
  
          $.each(json, function(i, v) {
  
              tt = parseInt(v.time);
  
                 if (tt &gt; timestamp) {
                  console.log(v.message);
                  appendLog($("&lt;div/&gt;").text('[' + v.username + ']' + v.message));
                  timestamp = tt
              }
          });
      }
  
      function appendLog(msg) {
          var d = log[0]
          var doScroll = d.scrollTop == d.scrollHeight - d.clientHeight;
          msg.appendTo(log)
          if (doScroll) {
              d.scrollTop = d.scrollHeight - d.clientHeight;
          }
      }
  });
  </code></pre>