httpweb-servicesionic4webapi

Fetch data from web API working in the browser but not working in the device ionic app


I build ionic app project and fetch data from SQL server using web API. The project working in the browser but not working in the device.

Here the code:

synAccountFromServer() {
    this.dataServices.getAccountFromServer().subscribe(
      d => {
        alert('Data Success');
      },
      err => {
        console.log('Error11: ' + JSON.stringify(err));
      }
    );


getAccountFromServer() {
    //alert('start get Datat from serve');   
    return this.http.get(this.urlGetAccounts);
  }

Solution

  • Normally this is because you are using http not https in the source.

    Check the value of this.urlGetAccounts has https at the start.

    If it does then it's probably a CORS issue, which is not an Ionic problem. It requires your server with the web api to be configured differently.