title: PHP/AJAX parse error
body: <p>I'm trying to take my PHP shoutbox and query using AJAX so that the page doesn't have to reload for shouts to be posted. Any help would be greatly appreciated!</p>
  
  <p>I am stuck - I keep receiving a parse error:</p>
  
  <pre><code>18:47:27.216 Details: parsererror
  Error:SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data 1 index.php:100:4
  </code></pre>
  
  <p>I've got shoutBox.php, which holds the HTML and AJAX:</p>
  
  <pre><code>&lt;head&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt; 
  
  &lt;script type="text/javascript"&gt;
  function sendChatMessage(msg)
  {
      $.ajax({
          type: "POST",
          url: "login/postData.php",
          data: {
              thisPost: msg   
          },
          dataType: "json",
          success: function(data)
          {
              if (data.error === false)
              {
                  $("#aData").text(data);
                  console.log("Post submitted.");
                  ajax.reload();
  
              }
              else
              {
                  console.log("Post was not submitted.");
              }
          },
          error: function(xhr, desc, err)
          {
              console.log(xhr);
              console.log("Details: " + desc + "\nError:" + err);
          }
      });
  }
  &lt;/script&gt;
  
  &lt;div class="shoutbox"&gt;
  
      &lt;h1 class="panel-heading"&gt;&lt;strong&gt;Federal&lt;/strong&gt; Communications Array&lt;/h1&gt;
      &lt;hr&gt;
      &lt;ul class="shoutbox-content"&gt;&lt;/ul&gt;
  
      &lt;div class="panel"&gt;
      &lt;form method="post"&gt;
      &lt;p&gt;
      &lt;table border="0" align="center" style="height: auto;" width="90%"&gt;
          &lt;tbody&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;a&gt;&lt;/a&gt;&lt;/td&gt;
                  &lt;td&gt;
  
                  &lt;div class="input-group"&gt;
  
                      &lt;span class="input-group-addon"&gt;Say:&lt;/span&gt;
                      &lt;input class="form-control" id="aData" name="post" maxlength='255' placeholder="Enter a message..."&gt;&lt;/input&gt;
  
                      &lt;div class="input-group-btn"&gt;
                          &lt;button class="btn btn-success" onClick="sendChatMessage(document.getElementById('aData').value); return false;"&gt;Send&lt;/button&gt;
                      &lt;/div&gt;
  
                  &lt;/div&gt;
  
  
                  &lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
      &lt;p&gt;
      &lt;/form&gt;
      &lt;/div&gt;
  
      &lt;div class="panel"&gt;
          &lt;table class="table table-striped"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th width="100px"&gt;Timestamp&lt;/th&gt;
                      &lt;th width="120px"&gt;Username&lt;/th&gt;
                      &lt;th width="980px"&gt;Message&lt;/th&gt;
                      &lt;th&gt;&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
  
  
          &lt;/table&gt;
      &lt;/div&gt;
  
  
  
  &lt;/div&gt;
  </code></pre>
  
  <p>And postData.php, which (is supposed to) execute the query.</p>
  
  <pre><code>&lt;?php
  
  ini_set('display_errors', 'On');
  error_reporting(E_ALL | E_STRICT);
  
  echo('Script begin.');
  
  require "dbconf.php"; // db details
  
  $connect = mysql_connect($host,$username,$password);
  
  mysql_select_db($db_name,$connect);
  
  $post = '';
  
      if(empty($_POST['aData'])) 
      {
          exit(json_encode([
          'error' =&gt; 'You must enter a message!',
          ]));
  
      } else {
  
          $post = trim($_POST['aData']);
  
          $playerUsername = $_SESSION['username'];
  
          $idQuery = "SELECT `id` FROM `members` WHERE `username`='$playerUsername'";
  
          $playeridQuery = mysql_query($idQuery);
  
          $playerID = mysql_result($playeridQuery, 0);
  
          mysql_query("INSERT INTO `shoutboxPosts` SET `id`='$playerID', `username`='$playerUsername', `post`='$post'");
  
      }
  
  
  
      exit(json_encode([
          'error' =&gt; false,
      ]));
  
  ?&gt;  
  </code></pre>