0

in My mobile application i want to fetch some data from server. I have read many article that the cause of my error is not having this code on xml file

<access origin="*"/> 

but i have added this in my config file. still my app is unable to fetch data from server please help

Rocking Birds
  • 165
  • 1
  • 17

2 Answers2

2

Firstly I recommend you to make sure you have installed plugins mentioned below.

cordova-plugin-network-information

cordova-plugin-whitelist

for more information about these plugins please visit cordova-plugin-whitelist and cordova-plugin-network-information.

In case still its not working then please add below tags in your platforms/android/androidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Hope this will work.

Community
  • 1
  • 1
0

You can install whitelist plugin using

phonegap plugin add https://github.com/apache/cordova-plugin-whitelist.git

command from CLI.

After that add <access> tags in config.xml

P.S. It's not good idea to add <access origin="*"/>, so add <access> tags only for the domains you will fetch data.

Some expamples of <access> tags.

<!-- Allow images, xhrs, etc. to google.com -->
<access origin="http://google.com" />
<access origin="https://google.com" />

<!-- Access to the subdomain maps.google.com -->
<access origin="http://maps.google.com" />

<!-- Access to all the subdomains on google.com -->
<access origin="http://*.google.com" />

You can read more at Plugin's documentation https://github.com/apache/cordova-plugin-whitelist

Denis Omeri
  • 610
  • 1
  • 9
  • 21