【发布时间】:2015-10-30 21:55:56
【问题描述】:
我正在使用最新的 PhoneGap 版本,并进行 ajax 调用。
$.ajax({
type : 'POST',
url : 'http://example.com/path to my API',
data : {d1: v1, d2: v2},
dataType : 'json',
success : function(data) {
console.log(data);
},
error : function(){
alert('Error');
}
});
当我在桌面浏览器或手机 PhoneGap Developer App 上测试我的应用程序时,它工作正常,但在构建应用程序 (.apk) 后,ajax 请求不起作用并且失败而不是成功。我已经完成了所有提到的配置,包括:
<access origin="*" />
<plugin name="cordova-plugin-whitelist" version="1" />
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
还在我的 HTML 中添加了 Content-Security-Policy 元标记并指向我的 API 所在的域:
<meta http-equiv="Content-Security-Policy" content="connect-src 'self' http://example.com/">
我正在使用 PhoneGap 在线构建服务来构建应用程序。 我真的需要帮助,因为我已经完成了我能找到的所有修复,但还没有成功。
【问题讨论】:
标签: android jquery ajax cordova phonegap-build