Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic app REST calls to webapi hosted on localhost works using ionic serve, but not when I use "ionic run"

Using Ionic serve -- My Ionic app returns data from my REST call to my webapi running on localhost.

But when I issue Ionic run , my REST API call fails. The error.data is blank, so I can't tell what the error is.

I am also able to hit the api of the rest call directly in my browser and see that it returns the data.

Would anybody please give me some pointers as to how to debug this, or why my http calls are failing in run mode?

like image 605
Rekha Jayaram Avatar asked Apr 24 '15 03:04

Rekha Jayaram


2 Answers

ionic serve run on browser and ionic run with devices[ios or android]

change localhost to ip address(in your system)

ex- 198.1.1.0:4000(eg.4000 is port number of local server)

and type(CLI)

ionic serve --address 198.1.1.0

check on Mobile browser type 198.1.1.0:4000

Note

like image 106
Anurag Pandey Avatar answered Nov 05 '22 23:11

Anurag Pandey


If you are using a live server for your REST application,you will run into CORS issues.

I would suggest, you use Ionic's proxy server to do all your request. You will not run in any OPTION request or null request response etc etc.

Check This Official Blog and, This will also be very helpful Ionic Proxy Example

like image 33
Karan Kumar Avatar answered Nov 05 '22 23:11

Karan Kumar