我試圖用這兩種方法調用http.get()
。Ionic 2 http.get()問題
首先:示
getResults(){
return this.http.get('http://localhost/api.php')
.toPromise()
.then(data => data.json());
}
錯誤:
3 122412 error EXCEPTION: Uncaught (in promise): Response with status:0 for URL: null
4 122413 error ORIGINAL STACKTRACE:
5 122413 error Error: Uncaught (in promise): Response with status: 0 for URL: null
..........
二:
所示getResults(){
return new Promise((resolve, reject) => {
this.http.get('http://localhost/api.php')
.map(res => res.json())
.subscribe(data => {
resolve(data);
}, (err) => {
reject(err);
});
});
}
錯誤:
2 925052 error EXCEPTION: Uncaught (in promise): Response with status:0 for URL: null
3 925052 error ORIGINAL STACKTRACE:
4 925053 error Error: Uncaught (in promise): Response with status: 0 for URL: null
.......
我應該使用哪種方法,可能是什麼問題?對於URL 0:
是。這解決了我的問題。 1投票了;) –