title: angular 2 service not calling a php file
body: <p>i'm learning angular 2 and i make a test to connect to a database, but i get an error that: SyntaxError: unexpected token &lt; in JSON at position 0.</p>
  
  <p>so i have my xampp working on port 80 or 443.
  the url of my test ( i'm using angular cli ) is: localhost:4200</p>
  
  <p>this is my attempt. i have a service with this method:</p>
  
  <pre><code>  getUsers(){
  return this._http.get('getusers.php')
    .map(res =&gt; res.json());
   }
  </code></pre>
  
  <p>the getusers.php file is located at the public folder.
  this is it's content. very basic just to get some results and send them back as json:</p>
  
  <pre><code> // set up the connection variables
      $db_name  = 'mydb';
      $hostname = 'localhost';
      $username = 'myusername';
      $password = 'mypass';
  
      // connect to the database
      $dbh = new PDO("mysql:host=$hostname;dbname=$db_name", $username, $password);
  
  
      $sql = 'SELECT * FROM users';
  
  
      $stmt = $dbh-&gt;prepare( $sql );
  
  
      $stmt-&gt;execute();
  
  
      $result = $stmt-&gt;fetchAll( PDO::FETCH_ASSOC );
  
  
      $json = json_encode( $result );
  
      echo $json;
  </code></pre>
  
  <p>so i add that in the component i import the service, initialize it in the constructor and subscribe:</p>
  
  <pre><code>  constructor(private _usersService: UsersService) {}
  
    ngOnInit() {
       this._usersService.getUsers()
         .subscribe(
           data =&gt; this.getUsers = JSON.stringify(data),
           error =&gt; alert(error),
           () =&gt; console.log("Finihed")
        );
    }
  </code></pre>
  
  <p>what am i missing here. i do tons of ajax call but first time with angular. maybe it's the ports? or something else i am missing?</p>
  
  <p>best regards</p>