title: Issue with Ajax Post "parsererror SyntaxError: Unexpected end of JSON input"
body: <p>I'm getting this error in my console and I've searched on google and here but I can't seem to find an answer that works.</p>
  <p>It's supposed to be a chat. This fragment is responsable for sending the messages to database</p>
  <p>Here's everything relevant in the console:</p>
  <pre><code>parsererror
  SyntaxError: Unexpected end of JSON input
      at parse (&lt;anonymous&gt;)
      at jquery-3.5.1.min.js:2
      at l (jquery-3.5.1.min.js:2)
      at XMLHttpRequest.&lt;anonymous&gt; (jquery-3.5.1.min.js:2)
  
  undefined // from console.warn(jqXHR.responseText)
  error   @   script.js:84
  c   @   jquery-3.5.1.min.js:2
  fireWith    @   jquery-3.5.1.min.js:2
  l   @   jquery-3.5.1.min.js:2
  (anonymous) @   jquery-3.5.1.min.js:2
  load (async)        
  send    @   jquery-3.5.1.min.js:2
  ajax    @   jquery-3.5.1.min.js:2
  send    @   script.js:67
  </code></pre>
  <p>In the Network tab it shows taht there's no response</p>
  <p>relevant JS code:</p>
  <pre><code>function send() {
      var text = $(&quot;#message&quot;).val();
      $(&quot;#message&quot;).val(&quot;&quot;);
      $.ajax({
          url:'Send.php',
          method: 'POST',
          dataType: 'json',
          data: { 'm': text },
          contentType: 'application/json',
          success: function () {
              console.log(&quot;succ&quot;);
              if (data.success) {
                  ostatnia = data.Id;
                  console.log(data);
              }
          },
          error: function (data, status, jqXHR) {
              console.log(data);
              console.log(status);
              console.log(jqXHR);
              console.warn(jqXHR.responseText);
          }
      });
  }
  </code></pre>
  <p>Send.php</p>
  <pre><code>ob_start();
  header('Content-Type: application/json');
  include('server.php');//has db connection and starts session
      $m = new Message();
      $data = 0;
  if(isset($_POST['m'])){
  
      
      if ($GLOBALS['conn']-&gt;connect_error) {
          $m-&gt;No($GLOBALS['conn']-&gt;connect_error);
      }
      else{
          $m-&gt;newMessage( $sesia, date(&quot;H:i:s d.m.y&quot;), $_POST['m'], $GLOBALS['conn']);
          $sql = &quot;INSERT INTO `chat`(`Id`, `Session_Id`, `Time`, `Content`, `Success`) VALUES (&quot;.$m-&gt;Id.&quot;,'&quot;.$m-&gt;Session_Id.&quot;','&quot;.$m-&gt;Time.&quot;','&quot;.$m-&gt;Content.&quot;',true)&quot;;//should work, I checked in phpMyAdmin
          if(!$GLOBALS['conn']-&gt;query($sql))
          {
              $m-&gt;No($GLOBALS['conn']-&gt;connect_error);
          }
          else{
          $m-&gt;weDidIt();
          }
      }
       $data = $m-&gt;returnMessage();
  }
  
     
      return json_encode($data);
  
  </code></pre>
  <p>chat.php(the main page)</p>
  <pre><code>&lt;script src=&quot;//code.jquery.com/jquery-3.5.1.min.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt;
  
  &lt;style&gt;
  //(...)
  &lt;/style&gt;
  
  &lt;div id=&quot;box&quot; name=&quot;box&quot; style=&quot;border: 2px solid black; background-color: azure; height: 50%; width: 50%; margin: 5% 25%; &quot;&gt;
  &lt;div id=&quot;czat&quot; name=&quot;czat&quot; &gt;
  &lt;/div&gt;
      &lt;/div&gt;
      &lt;input type=&quot;text&quot; id=&quot;message&quot; name=&quot;message&quot; style=&quot;margin-left:25%; width:40%&quot;/&gt;
      &lt;input type=&quot;submit&quot; id=&quot;wyslij&quot; style=&quot;width:10%;&quot;/&gt;
  
  </code></pre>