我正在尝试创建一个移动应用程序,它具有到数据库的API连接。有时我没有得到任何错误,这一切都可以与API,但通常,我得到这种错误。(见下图)
This is the error I got from the Dev Tools
这是我的代码:
let headers = new Headers ({
'Accept' : 'application/json',
'Authorization' : 'Bearer ' + this.token
});
let options = new RequestOptions({ headers : headers });
return new Promise((resolve, reject) => {
this.http.get('https://mywebsite.com/api', options)
.toPromise()
.then((response) =>
{
if(response){
console.log('API Response : ', response.json());
var _response = response.json();
resolve(response.json());
}
this.loadingSrvc.hide();
})
.catch((error) =>
{
this.loadingSrvc.hide();
if(error){
console.error('API Error : ', error.status);
console.error('API Error : ', JSON.stringify(error));
reject(error.json());
}
});
});
我在用
和MySQL—数据库的phpMyAdmin
我的主要困境是,有时它起作用,有时不起作用,我甚至不知道原因。