Cross-Domain requests with cordova

2019-01-29 08:28发布

I realize an application with which I'm supposed to send data via http with $ .getJSON.

My problem: When I test with chrome or another browser its pass but when I generate the apk and I test on a phone its does not pass.

I think that it is certainly a problem of configuration of cordova (version 6.4.0)

JS

 function jsoncallback(data){
     alert(data.service+" bien enregistré");
        $('#load').show();
            $('#imload').hide();
    }

function Service(service) {
    var var1 =$('#var1').val();
     var var2 =$('#var2').val();
   if(var1 == 0 || var2 == 0){
       alert('Service impossible.. ');
    }else{
        if(confirm("Choix : "+var1+" | "+var2)){
            $('#load').hide();
            $('#imload').show();
            $.getJSON("http://xxxx.xxxx.xx/service.php?var1="+var1+"&var2="+var2+"&jsoncallback=?");
         }
    }
}

Config.xml

<access origin="*" />
   <plugin name="cordova-plugin-whitelist" spec="1" />
   <plugin name="cordova-plugin-whitelist" version="1" />

   <allow-intent href="http://*/*" />
   <allow-intent href="https://*/*" />
   <allow-intent href="tel:*" />
   <allow-intent href="sms:*" />
   <allow-intent href="mailto:*" />
   <allow-intent href="geo:*" />
   <allow-navigation href="http://*/*" />
   <allow-navigation href="https://*/*" />
   <allow-navigation href="data:*" />

   <platform name="android">
       <allow-intent href="market:*" />
   </platform>
   <platform name="ios">
       <allow-intent href="itms:*" />
       <allow-intent href="itms-apps:*" />
   </platform>

1条回答
Evening l夕情丶
2楼-- · 2019-01-29 09:02

Cordova 6.4.0 have many issues regarding plugins, ajax request and many more

There's still no fix on that issues

Many of SO users going to downgrade cordova to start working their project into it

If your code working in browser then you have to downgrade your cordova version for now.

Check issues and answers for below questions you will get more understanding on my point.

1) Cordova 6.4.0: android platfrom install Whitelist error

2) Cordova Ajax request pending for ever

Use below code to downgrade cordova version

npm uninstall -g cordova

npm install -g cordova@6.2.0
查看更多
登录 后发表回答