I'm new to angular 2.I'm using http.get() for fetching a data from php file.this is my php file
<?php
header("Access-Control-Allow-Origin:*");
header('Access-Control-Allow-Headers: X-Requested-With');
include('connection.php');
$fd=new Connect();
$fd->__construct();
$data=array();
$select=mysql_query("SELECT * FROM userData'")or mysql_error();
$sql=mysql_num_rows($select);
if($sql>0)
{
while($row=mysql_fetch_array($select))
{
}
}
header('Content-Type: application/json');
echo json_encode($data);
?>
Here I used
header("Access-Control-Allow-Origin:*");
header('Access-Control-Allow-Headers: X-Requested-With');
header('Content-Type: application/json');
to get this php file in json file still it's not working.I got whole php file in response instead of json file. this is my angular 2 component part
export class LoginComponent {
private data;
getData:string;
constructor (private http:Http){}
Getlogin(){
//this.httpService.getUserData()
this.http.get('dev/AngularWithPhp/login.php')
.map(res => res.json())
.subscribe(
data=>this.getData = JSON.stringify(data),
error =>alert(error),
()=>console.log("done"));
}
So what's the problem?give me suggestions...