Home:ALL Converter>Ajax call to localhost from app running on IPhone device using Expo

Ajax call to localhost from app running on IPhone device using Expo

Ask Time:2017-12-14T11:18:16         Author:ChristKho

Json Formatter

I am using the logic below for choosing an ip address for making ajax call to Api which is running on localhost and its working fine when I use emulator on my laptop, but when I use expo on an IPhone device to load my app the ajax call fails and can not make the connection with the Api, I also tried my machine local ip in network and 127.0.0.1 but none of them works.

const SERVER_URL = __DEV__ ? Platform.select({ ios: "http://localhost:5000", android: "http://10.0.2.2:5000" }) : "https://exmple.com"

Author:ChristKho,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/47805341/ajax-call-to-localhost-from-app-running-on-iphone-device-using-expo
yy