Using PHP I am echoing a response from SQL Server by using:
echo json_encode($total);
Just as a test, before I echo, I run error_log(json_encode($total)) which outputs the object as:
[{"address":"Mitchell Hwy",
"description":"Nyngan Eastbound STC",
"site_name":"T0242",
"heading":"East",
"vehicle_class":"B double",
"vehicle_class_id":"10",
"avg_speed":"69.27",
"volume":"46"}]
Which is exactly what I want to receive within Angular 2's http response. My Angular 2 code is:
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(url, sentArray,{
headers: headers
}).subscribe(
result => returnedJSON = result,
() => console.log("Failed..."),
() => console.log(returnedJSON)
);
This prints a 'Response' object in the console, where the Response 'body' is the returned PHP code that I want.
Response {_body: "[{"address":"Mitchell Hwy","description":"Nyngan E…_id":"Total","avg_speed":"67.35","volume":"262"}]",
status: 200,
ok: true,
statusText: "OK",
headers: Headers…}
My questions are: Why am I receiving an entire response object? Is this because I used POST HTTP request - or just the way the Angular 2 receives the response? How do I isolate just the Response body?
I assume I am doing everything correctly in PHP since I am logging the exact output that I want. I assume that this is something to do with my Angular 2 code...