代码之家  ›  专栏  ›  技术社区  ›  Oliver Primo

Ionic API错误:Error.json不是函数

  •  0
  • Oliver Primo  · 技术社区  · 7 年前

    我正在尝试创建一个移动应用程序,它具有到数据库的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

    我的主要困境是,有时它起作用,有时不起作用,我甚至不知道原因。

    0 回复  |  直到 6 年前