2017-01-02 129 views
0

我知道一个应用程序,我应该用$ .getJSON通过http发送数据。与科尔多瓦的跨域请求

我的问题:当我用铬或其他浏览器测试其通过,但是当我生成的apk和我在手机上测试它没有通过。

我认为这肯定是科尔多瓦的配置的问题(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> 
+0

[http://stackoverflow.com/questions/30060534/ajax-requests -fail-后升级到科尔多瓦-5-0-科尔多瓦-android4-0](http://stackoverflow.com/questions/30060534/ajax-requests-fail-after-upgrading-to-cordova-5- 0-cordova-android4-0) –

回答

2

Cordova 6.4.0有关于插件的许多问题,ajax请求和更多

仍然没有修复o n表示发出

很多,因此用户要降级科尔多瓦开始工作,他们的项目到它

如果你的代码在浏览器中工作,那么你必须降级科尔多瓦版本现在。

查看以下问题的问题和答案,您将会更了解我的观点。

1)Cordova 6.4.0: android platfrom install Whitelist error

2)Cordova Ajax request pending for ever

使用以下代码来降级版本科尔多瓦

npm uninstall -g cordova 

npm install -g [email protected] 
+0

@KirankumarDafa可能并非如此。它适用于最新的科尔多瓦版本。你有没有正式的错误记录来支持这个事实? – Gandhi

+0

@甘地,'不,我没有!'我只是建议降级目前的项目版本,如果它在更新最新版本之前工作正常 –

+0

降级版本绝对不是答案,因为它可以很好地与最新版本 – Gandhi