使用cordova的跨网域请求 [英] Cross-Domain requests with cordova

查看:228
本文介绍了使用cordova的跨网域请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的问题:当我使用chrome或其他浏览器测试时通过,但是当我生成的apk,我测试在手机上它不通过。



我认为这当然是配置cordova的问题)



JS

  function jsoncallback(data){
alert(data.service +bienenregistré);
$('#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')。
$('#imload')。show();
$ .getJSON(http://xxxx.xxxx.xx/service.php?var1 =+ var1 +& var2 =+ var2 +& jsoncallback =?);
}
}
}

Config.xml

 < access origin =*/> 
< plugin name =cordova-plugin-whitelistspec =1/>
< plugin name =cordova-plugin-whitelistversion =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>


解决方案

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



这个问题还没有解决



许多SO用户会降级cordova,开始将其项目投入使用



如果您的代码在浏览器中工作,那么您必须降级您的cordova版本



$ b

查看下列问题的问题和答案,您将对我的观点有更深入的了解。 b

1) Cordova 6.4.0:Android platfrom install白名单错误



2)



  npm uninstall -g cordova 

npm install -g cordova@6.2.0


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>

解决方案

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

这篇关于使用cordova的跨网域请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆