title: Ajax response type is text/html, how to get response type of application/json?
body: <p>I have specified Ajax response on server side as:</p>
  
  <pre><code>header("Content-Type: application/json; charset=utf-8");
  </code></pre>
  
  <p>When I check after my request completion, I get the following response header:</p>
  
  <pre><code>Content-type:text/html; charset=UTF-8
  </code></pre>
  
  <p>In my response, I am sending the following status based on whether the request got completed successfully or failed or there is an exception.</p>
  
  <pre><code>if($stmt-&gt;rowCount() == 0) {
      // Create SQL Statement
      foreach ($payload_jsonDecoded as $i =&gt; $item) {
  
          $sql = $sql . "some insert query";
      }
  
      // Prepare statement
      $insertstmt = $conn-&gt;prepare($sql);
  
      // execute the query
      $insertstmt-&gt;execute();
  
  
      if($insertstmt-&gt;rowCount() &gt; 0){
          $json = json_encode(array(
              "status" =&gt; true,
          ));
      }
      else{
          $json = json_encode(array(
              "status" =&gt; false,
          ));
      }
  }
  else{
      $json = json_encode(array(
          "status" =&gt; false,
      ));
  }
  
  echo $json;
  die();
  </code></pre>
  
  <p>On client side, I am using:</p>
  
  <pre><code>$.ajax({
              url: 'path',
              type: "POST",
              data: jsonObj,
              //dataType: "jsonp",
              processData: false,
              contentType: "application/json; charset=utf-8",
                success: function (output, status, xhr) {
                    console.log(xhr.getResponseHeader("Content-Type"));
  </code></pre>
  
  <p>My logic as well as code works, but on the client side, my response contains the following messages which messes up the response message and hence I am not able to display correct message to the end users. </p>
  
  <pre><code>Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0
  
  Warning: Cannot modify header information - headers already sent in Unknown on line 0
  </code></pre>
  
  <p>Any insights would be grateful. </p>