2017-01-02 126 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