config.service.ts file ->
constructor (private http:Http){
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
this.options = new RequestOptions({ headers: headers });
this.API_BASE_URL='http://localhost/confalerts/api/savetodb.php';
}
saveConference(data){
return this.http.post(this.API_BASE_URL,data,this.options).map((res)=>res.json(),(err)=>err);
}
Service call in component.ts ->
let data=this.newconfForm.value;
let pair={action_type:"saveconference"};
data={...data,...pair};
this.configSvc.saveConference(data).subscribe((jsondata)=>{
console.log('successfully called');
},(err)=>{
});
PHP File ->
`header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json; charset=utf-8');
$postData=json_decode($_POST['data'],true);
print_r($postData);`
My problem is-> PHP file throws the NOTICE:
Notice: Undefined index: Formdata in
C:\xampp\htdocs\confalerts\api\savetodb.php on line 8
$postData=json_decode(file_get_contents('php://input'),true);
is an easy hack but i'll be uploading files in this form as well so I dont wish to use the php://input
file.
What could be a possible solution?
I tried appending headers, but header.append()
is apparently not a supported function.