title: Angular 2: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
body: <p>I am using Angular 2 and I want to send the json data to a php file. When I try to send the data using the post request, it says "SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data". When I look at the network tab it says status 200, so it sent it. I am not sure what I am doing wrong, but I would appreciate if someone could look this over.</p>
  
  <p><strong>Here is the data service I am using for the post request</strong></p>
  
  <pre><code>sendData(data): Observable&lt;Object&gt;{
   let url = "test.php";
   let encoded_data = JSON.stringify({data});
   console.log('encoded', encoded_data);
      let headers = new Headers({ 'Content-Type': 'application/json; charset=utf-8' });
      let options = new RequestOptions({ headers: headers });
  
      return this.http.post(url, encoded_data).map(
          (res: Response) =&gt; res.json() || {}
      );
  }
  </code></pre>
  
  <p><strong>I use it in my component like this.</strong></p>
  
  <pre><code>sendDatatoServer(){
    this.dataService.sendData(this.data)
       .subscribe(
          data =&gt; {
             console.log('the data', data);
          },
         (err) =&gt; console.log(err),
         () =&gt; console.log("data success!!")
        );
   }
  </code></pre>
  
  <p><strong>My json data looks somewhat like this when it is stringified.</strong></p>
  
  <pre><code>{"data": [{"title": "sometext" }, {"title": "sometext" }]}
  </code></pre>
  
  <p><strong>Here is the test.php file I have so far. I am not sure if this is correct or not, but it doesnt send any response.</strong></p>
  
  <pre><code>&lt;?php
  
  
  header("Access-Control-Allow-Origin: *");
  header("Content-Type: application/json; charset=UTF-8");
  
   $postdata = file_get_contents("php://input");
   $request = json_decode($postdata);
  
   echo $request;
  </code></pre>