I'm trying to make a post request with Angular 4 with this code to send lat and lng parameters:
let data = {lat: this.newLat, lng: this.newLng};
this.http.post(url, data)
.map(response => response.json())
.subscribe(getResponse => console.log(getResponse));
On the server side, I have the following php snippet:
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
if ( isset($_POST['lat'], $_POST['lng']) ) {
$response['msg'] = 'ok';
} else {
$response['msg'] = 'not ok';
}
echo json_encode($response);
The response from the server is unfortunately always 'not ok'
. Any ideas how to solve this? The $_POST
variable is always an empty array