Search code examples
ajaxcordovaxmlhttprequestphonegap-build

Cross-domain XHR with cordova-plugin-whitelist on PGB is Failing


Using :

  1. PGB cli-5.2.0
  2. cordova-plugin-whitelist (i've tried both https://build.phonegap.com/plugins/4178 and plugins/3401 )
  3. Refering to ( https://github.com/lukesmith123/whitelist-2/blob/18a8ce4/README.md ) i added <allow-navigation href="*" /> , <allow-intent href="*" />, <access origin="*" />
  4. My app is using an ajax request to get data from http that has "Access-Control-Allow-Origin", "*".

But still get: Error Failed to load resource: the server responded with a status of 404, yet on localhost it works just fine.

What could i be missing?


Solution

  • Finally got it working.

    I put this CSR metta tag in the html <head>

    <meta http-equiv="Content-Security-Policy" content="default-src *; style-src *  'unsafe-inline'; script-src *  'unsafe-inline'; media-src *">
    

    And put this cordova-plugin-whitelist in the config.xml

    <gap:plugin name="cordova-plugin-whitelist" source="npm" />
    <allow-navigation href="http://*/*" />
    <allow-intent href="https://*/*" />
    

    Phew!!!