The when I try $ ionic run ios -l -c -s I see that the .error() is being called not .success()
The navigator.connection.type logs wifi
However when I look at the logs on 192.168.1.10 for apache I see that the file.txt was returned, status 200 with the correct amount of bytes. Not sure why the $http.success is not firing?
Some details from my setup:
$ ionic info
OS: Mac OS X Yosemite
Node Version: v0.12.0
Cordova CLI: 4.2.0
Ionic Version: 1.0.0-rc.0
Ionic CLI Version: 1.3.13
Xcode version: Xcode 6.1.1 Build version 6A2008a
ios-sim version: 3.1.1
@sarale Are you thinking it is a cors problem? The http://192.168.1.10:80/file.txt is just for testing purposes and is a local apache server on the same IP that the ionic run would bind to. If I build an android apk and install it to the device it does work. So seems to be a simulator thing?
Why not install gapDebug? It’s free and you can verify that really happens in the simulator with plugins and errors, you maybe out there specifically error occurring.
@sarale Yes I did try http://192.168.1.10/file.txt from a browser and even from Safari browser inside the emulator and the test little file does come back.
Running $ ionic run ios -l -c -s brings back the following:
Running dev server: http://192.168.1.10:8100
Running live reload server: http://192.168.1.10:35729
So the apache test server is running on the same machine as the simulator. But even if I change the http:// to anything else I still just get the .error() function being called.
@sioesi I must be honest, I am new to the cordova world, do not even know about gapDebug. Will have a look and see if I can get it installed.
Thanks for the help. Not sure what is happening here. Its such a basic thing, just trying to get $http to return a valid file form the simulator.
I must just add (to be clear), if I build an android app the $http works fine. I am just having the issue inside the ios emulator and android emulator.
Gabdegub is, you could have a look, I occupy for a similar mistake and helped me a lot, available for both platforms free tool I leave the link, brings a good tutorial to configure the devices and emulators here.
@sioesi Thanks for the GapDebug info. I downloaded GapDebug, ran my app with just $ ionic run ios, gapDebug then brought up the Simulator, I loaded the app from the simulator and it registered with gapDebug. In the console of gapDebug the $http worked without an issue. So it must be something with trying $ ionic run ios -l -c -s in a live environment. At least now I have a nice debug environment.
Good thing you have served, however try to test your app in a real device, I had many problems with the simulator once in a physical device all problems were solved and also GapDebug helped me a lot Good luck!
This error is due by CORS problem of your destination server which does not support “localhost” headers.
Infact if you execute your code from a Device or from the simulator without node server (so without -l -c -s) it gonna work perfectly.