我最近更新了我的Xcode到12.0,我在我的mac上安装了最新的iOS 14和Cordova 10.0.0。我还将UIWebview
更改为WKWebViewOnly
。我还引用了以下链接,以在配置文件中启用该选项:
Ajax Not working in IOS 9.0 Cordova
因此,我的配置文件如下所示
<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>
我的代码在Android中运行良好,但我在单击按钮时调用的以下代码(在设备就绪事件被调用之后)失败:
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();
}
});
我还尝试将以下内容添加到index.html中
<meta http-equiv="Content-Security-Policy" content="connect-src *; style-src 'self' 'unsafe-inline'; media-src *">
我假设Cordova在Ajax上运行得很好,事实上,在我的旧版本Cordova和Xcode中,它运行得很好,但我最近遇到了这个问题。
发布于 2021-01-21 06:46:15
请将crossDomain : true添加到您的ajax参数
https://stackoverflow.com/questions/64064651
复制