title: parsererror SyntaxError: Unexpected end of JSON input
body: <p>When I add <code>if(isset($_POST['uplprofimg']))</code>, I get the error:</p>
  
  <pre><code>parsererror SyntaxError: Unexpected end of JSON input
  </code></pre>
  
  <p>If I exclude the php if isset post function, the code works perfectly.</p>
  
  <p>So, PHP:</p>
  
  <pre><code>if(isset($_POST['uplprofimg'])){ //← This  if broke my code &gt;:(
          //Works if I remove the ↑
          if($_FILES['imagefile']['size'] &gt; 5242880){
              $ress = "&lt;div class='error'&gt;Max file size is 5MB&lt;/div&gt;";
              echo json_encode(array('response' =&gt; false,'ress' =&gt; $ress));
          }else{
              $imgtype = pathinfo($_FILES['imagefile']['name'],PATHINFO_EXTENSION);
              if(!in_array($imgtype,array('jpg','jpeg','png','gif'))){
                  $ress = "&lt;div class='error'&gt;Only &lt;b&gt;jpg&lt;/b&gt;, &lt;b&gt;jpeg&lt;/b&gt;, &lt;b&gt;png&lt;/b&gt; and &lt;b&gt;gif&lt;/b&gt; files are allowed (".$imgtype.")&lt;/div&gt;";
                  echo json_encode(array('response' =&gt; false,'ress' =&gt; $ress));
              }else{
                  $newimgname = "/profile_picture/".random_num($length = 8).time().random_num($length = 8).".".$imgtype;
                  $newimgnameserv = $_SERVER['DOCUMENT_ROOT'].$newimgname;
                  if(move_uploaded_file($_FILES['imagefile']['tmp_name'],$newimgnameserv)){
                      $upuser = $mysqli-&gt;prepare('UPDATE accinfo SET profilepic = ? WHERE username = ?');
                      $upuser-&gt;bind_param('ss',$newimgname,$username);
                      $check = $upuser-&gt;execute();
                      if($check == true){
                          echo json_encode(array('response' =&gt; true));
                      }else{
                          $ress = "&lt;div class='error'&gt;SQL Error&lt;/div&gt;";
                          echo json_encode(array('response' =&gt; false,'ress' =&gt; $ress));   
                      }
                  }else{
                      $ress = "&lt;div class='error'&gt;Couldn't move the file. Please try again later.(".$newimgname.")&lt;/div&gt;";
                      echo json_encode(array('response' =&gt; false,'ress' =&gt; $ress));
                  }
              }
          }
      }
  </code></pre>
  
  <p>and JS:</p>
  
  <pre><code>$("#uploadimgform").on("submit",function(event){
      event.preventDefault();
  
      var formData = new FormData(this);
  
      $("#uploadlistener").html("&lt;img src='/images/load.gif' width='50px' /&gt;");
  
      $.ajax({
          type: 'POST',
          url: "/system/requests.php",
          data: formData,
          dataType: "json",
          cache: false,
          contentType: false,
          processData: false,
          success: function(data){
              if(data.response === true){
                  $("#bodyfader").fadeOut("slow");
                  $("#expandedupl").fadeOut("slow");
                  $("#uploadlistener").html("");
              }else{
                  $("#uploadlistener").html(data.ress);
                  $('#profilepic').css('background', 'url(/images/defaultprof.png)');
                  $("#profilepic").css("background-size","cover");
                  $("#profilepic").css("background-position","center");
              }
          },
          error: function(jqXHR, textStatus, errorThrown) {
              console.log(textStatus, errorThrown);
          }
      });
  });
  </code></pre>
  
  <p>If I remove the <code>if(isset($_POST['uplprofimg'])){...}</code>, the code works. But if I add it there, I get the json error. What is going on?</p>
  
  <p>HTML Form:</p>
  
  <pre><code>&lt;form method='POST' enctype="multipart/form-data" id='uploadimgform' style='display: none;'&gt;
       &lt;input type='file' id='upload' name='imagefile' accept="image/x-png,image/gif,image/jpeg" /&gt;
       &lt;input type='submit' id='uploadconf' name='uplprofimg' /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is how the form is submitted:</p>
  
  <pre><code>$("#upload").change(function(){
      if(this.files[0].size &gt; 5242880){
          $("#uploadlistener").html("&lt;div class='error'&gt;Maximum file size is 5MB.&lt;/div&gt;");
          $("#upload").val("");   
      }else{
          $("#uploadimgform").submit();
          readURL(this);
      }
  });
  </code></pre>
  
  <p>I have no idea why, but I did this:</p>
  
  <pre><code>formData.append('uplprofimg',1);
  </code></pre>
  
  <p>and the code works. Someone can explain this?</p>