該函數發出的HTTP請求以URL作爲參數。
get_http_response(url) {
this._http.get(url) /*this make http request to server*/
.map((response: Response) => {
response.json();
this.responseStatus = response.status; /* local variable to restore status code. */
}) /*this get response back and map it*/
// ...errors if any
.catch((error: any) => Observable.throw(error.json().error || 'Server error')
)
.subscribe(
resdata => {
this.getdata = resdata; /*local variable to store data. */
console.log("fetched data =>" +this.getdata);
console.log("status code =>" + this.responseStatus);
}
);
}
我認爲這將解決你的問題,如果你上後下的任何錯誤評論。
謝謝。