Ikram Bk
Ikram Bk

Reputation: 177

ionic http get doesn't work

My project back-end is implemented with VS with the port number 26309 and I am implementing my front-end with ionic in notepad++ .

My problem is that the controller can't retrieve data through :$http.get("http://localhost:26309/api/User/getAll/").

SOLUTION

I solved the problem by :

1- adding in the config.xml the permission <allow-navigation href="http://*/*"/>

2-installing cordova-plugin-whitelist ionic plugin add cordova-plugin-whitelist

3-add control-allow-origin extention to chrome :https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi/related?hl=en-US

And finally : specifying the type of data returned by the back-end controller by adding this code to my Global.asax in Application_start method :

config.Formatters.JsonFormatter.SerializerSettings.Formatting =
                Newtonsoft.Json.Formatting.Indented;
            config.Formatters.Remove(config.Formatters.XmlFormatter);

Hope this helps someone

Upvotes: 1

Views: 600

Answers (3)

Dan Bucholtz
Dan Bucholtz

Reputation: 713

Localhost points to the local device, not your development machine. @Simon is correct.

Thanks, Dan

Upvotes: 0

Simon Sch&#252;pbach
Simon Sch&#252;pbach

Reputation: 2683

You use ionic. Did you tried this on a device? Because you will never reach your server on your pc with localhost from a device. You have to use an ip address or domain name.

Upvotes: 0

JohnPaul
JohnPaul

Reputation: 710

Try this,

$http.get('http://localhost:26309/api/User/getAll/')
   .success(function(data){
       //your code
   }
    .error(function(error){
       //your code
   }

Upvotes: 2

Related Questions