-1

I am trying to fetch data using WebApi which runs on localhost:58682/home/index1 in Ionic2 app which runs on localhost:8100.
I am getting the following error message.

XMLHttpRequest cannot load http://localhost:58682/home/index1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

My service.ts file

 @Injectable()
export class ResponseService{
 
 private responseUrl='http://localhost:58682/home/index1';
   getresponseDetails()
    {
        return this.http.get(this.responseUrl).map(res=>res.json());
    }
    }

ionic.config.json

{
  "name": "App",
  "app_id": "90594fdf",
  "type": "ionic-angular",
  "proxies":[
    {
      "path":"/home",
      "proxyUrl":"http://localhost:58682/home"
    }
  ]
}

I went through some CORS blogs but couldn't fix it. What exactly is going wrong?

priyank bhardwaj
  • 119
  • 2
  • 15

1 Answers1

1

Try again using this plugin in your browser.

It allows to you request any site with ajax from any source, no matter http/https discrepancies and the like. Practically adds the Allow-Control-Allow-Origin: * header in the response.

Please keep in mind that this is a band-aid solution. Your server response has to actually have the 'Access-Control-Allow-Origin': '*' header, preferably with a more specific value than *.

maninak
  • 2,633
  • 2
  • 18
  • 33