title: How to post json data to a php script with $http.post
body: <p>I've been having this problem for a while and tried many solutions which haven't worked.
  I am trying to use $http.post to send json data to a php script named processCustomers.php which is part of my API</p>
  
  <p>The post request is</p>
  
  <pre><code>angular.extend(obj, {id: id});
    $http({
      method: 'POST',
      url: '../API/processCustomers.php',
      headers: { 'Content-Type': 'application/json' },
      dataType: 'json',
      data: obj
     }).success(function (data) {
      console.log(data);
    });
  };
  </code></pre>
  
  <p>and the processCustomers is</p>
  
  <pre><code>$newCustomers = filter_has_var(INPUT_POST, 'newCustomer');
  if ($newCustomers) {#request to add new customer
  
      $exceptionalFields = ['customerID']; //
  
      $customersJSON = json_decode(filter_input(INPUT_POST, "newCustomer"));
  
  
  
      if (json_last_error() &gt; 0) {
          echo DotCom::systemFeedBack("Sorry customer not created unknown error", "data sent is not a json object", 303);
          return;
      }
  
  
  
      foreach ($customersJSON as $key =&gt; $customer) {
          $parameterTypes = ""; # order determined by the sql returned by validateInputData()
  
  
      $entries = $func-&gt;validateInputData($tableMetaData,$customer, $parameterTypes, $exceptionalFields);
  
  
      if (!is_array($entries)) {
          echo $entries;
          return;
      }
  
       $results = $customers-&gt;createCustomer($entries, $parameterTypes, $link,$status);
  </code></pre>
  
  <p>When I send the request, the console in the browser says the response is text/html instead of application/json.I looked through many tutorials and examples and I also have tried the folowings:
  removing the headers and datatype - no effect
  wrapping the obj in JSON.stringify - results in header changing to application/x-www-form-urlencoded</p>