I am getting this(JSON.parse: unexpected end of data at line 1 column 1 of the JSON data )error in my Response from the server. I did console.log for JSON.stringify(user) and it shows the object as it should be.Even the data is been stored to database. this is my service.ts
signup(user: User) {
const body = JSON.stringify(user);
const headers = new Headers({'Content-Type': 'application/json'});
const requestOptions = new RequestOptions({method : RequestMethod.Post,headers : headers});
return this.http.post('url', body,requestOptions)
.map((response: Response) => response.json())
}
signin(user: User) {
const body = JSON.stringify(user);
const headers = new Headers({'Content-Type': 'application/json'});
return this.http.post('url', body, {headers: headers})
.map((response: Response) => response.json())
}
logout() {
localStorage.clear();
}
isLoggedIn() {
return localStorage.getItem('token') !== null;
}
this is my php file
<?php
include "db.php";
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$data = json_decode(file_get_contents("php://input"));
//print_r($data);
/*$firstname = mysql_real_escape_string($data->firstName);
$lastname = mysql_real_escape_string($data->lastName);
$email = mysql_real_escape_string($data->email);
$password = mysql_real_escape_string($data->password);*/
$sql = "INSERT INTO `tbl_user`(`firstname`, `lastname`, `email`, `password`) VALUES ('$data->firstName','$data->lastName','$data->email','$data->password')";
if($data->firstName){
$qry = $conn->query($sql);
}
$conn->close();
?>