Cordova 10.0 Ajax无法在iOS 14中运行,但在Android中可以正常运行 [英] Cordova 10.0 Ajax not working in iOS 14 but working fine in Android

查看:70
本文介绍了Cordova 10.0 Ajax无法在iOS 14中运行,但在Android中可以正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将Xcode更新为12.0,并且在Mac上安装了最新的iOS 14和Cordova 10.0.0.我也将 UIWebview 更改为 WKWebViewOnly 我还参考了以下链接以在配置文件中启用该选项:

Ajax无法在IOS 9.0 Cordova中使用

所以,我的配置文件看起来像这样

 <访问源="*"/>< allow-intent href =" http://*/*"/>< allow-intent href =" https://*/*"/>< platform name ="ios">< allow-intent href =" itms:*"/>< allow-intent href =" itms-apps:*"/>< preference name ="AllowUntrustedCerts"值=开"./>< preference name ="InterceptRemoteRequests";值=全部";/>< preference name ="NativeXHRLogging";value =满"/>< preference name =" WKWebViewOnly"值=真"/><功能名称="CDVWKWebViewEngine">< param name ="ios-package"value ="CDVWKWebViewEngine";/></feature>< preference name =" CordovaWebViewEngine"value ="CDVWKWebViewEngine";/></platform> 

我的代码在Android上运行良好,但是单击按钮(在调用设备就绪事件后)调用的以下代码失败:

  var postData ="& UserName ="+ user1;$ .ajax({type:'POST',数据:postData,网址:"http://webaddress.com",超时:120000,complete:function(jqXHR,textStatus){alert("done"));},成功:function(dataMain){},错误:功能(xhr,ajaxOptions,throwError){//console.log(data);alert(错误" + ajaxOptions +" + thrownError);//如果((ajaxOptions ==="timeout")){openAlertMsg(timeoutMsg);}hideLoading();}}); 

我还尝试将以下内容添加到index.html

 <元http-equiv ="Content-Security-Policy"content ="connect-src *;style-src'self''unsafe-inline';media-src *> 

我认为Cordova在Ajax上运行正常,实际上,在我的较旧版本的Cordova和Xcode中,它运行良好,但是最近才遇到此问题.

解决方案

请在您的Ajax参数中添加crossDomain:true

I recently updated my Xcode to 12.0, and I have the latest iOS 14, and Cordova 10.0.0 on my mac. I also changed the UIWebview to WKWebViewOnly I have also referred to the following link to enable the option in the config file:

Ajax Not working in IOS 9.0 Cordova

So, my config file looks something like this

<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" /> 
<platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
<preference name="AllowUntrustedCerts" value="on" />
<preference name="InterceptRemoteRequests" value="all" />
<preference name="NativeXHRLogging" value="full" />
<preference name="WKWebViewOnly" value="true" />
    <feature name="CDVWKWebViewEngine">
        <param name="ios-package" value="CDVWKWebViewEngine" />
    </feature>
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
</platform>

My code works fine in Android, but the following code which I call on the click of a button (after the device ready event has been called) fails:

var postData = "&UserName=" + user1;
$.ajax({type: 'POST',
data: postData, url: "http://webaddress.com",
timeout:120000,
complete: function(jqXHR, textStatus) {alert("done");},
                   success: function(dataMain){
                   
                   },
                   error: function(xhr, ajaxOptions, thrownError){
                   //console.log(data);
                   alert("error  " + ajaxOptions + "  " + thrownError);
                   //    if (ajaxOptions === "timeout") { openAlertMsg(timeoutMsg); }
                   hideLoading();
                   }
                   });

I also tried to add the following to the index.html

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

I assume Cordova runs fine with Ajax, in fact, in my older version of Cordova and Xcode, it was running fine, but am facing this issue very recently.

解决方案

please add crossDomain : true to your ajax args

这篇关于Cordova 10.0 Ajax无法在iOS 14中运行,但在Android中可以正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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