在发布模式下运行Android Cordova应用程序时,Ajax调用失败 [英] Ajax calls fail when running Android Cordova app in Release mode

查看:119
本文介绍了在发布模式下运行Android Cordova应用程序时,Ajax调用失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android上以发布模式运行该应用程序(在iOS上运行)时,AJAX调用失败.这是我在Chrome开发工具中看到的错误(确实是一个警告):

AJAX calls fail when running the app in release mode on Android (works on iOS). This is the error (a warning really) I see in the Chrome Dev Tools:

显示了临时标题

Request URL:https://server.com/api/index.php?ticket=ST-111111-ABCDEFG-cas

Request Headers
Provisional headers are shown
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Origin:file://
User-Agent:Mozilla/5.0 (Linux; Android 6.0; Google Nexus 5 - 6.0.0 - API 23 - 1080x1920 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.0.0 Mobile Safari/537.36
Query String Parametersview sourceview URL encoded
ticket:ST-111111-ABCDEFG-cas

Form Dataview sourceview URL encoded
request:{"param1":"val1","param2":"val2"}

在调试"模式下一切正常. 我去年针对Android的发行版仍然运行良好.因此,它可能与Cordova的新版本有关. 这是我拥有的工具版本:

Everything works fine on Debug mode. My last year release build for Android is still working fine also. So it may be related to the new version of Cordova. Here is the tools versions I have:

  • 节点版本:v4.4.3
  • 科尔多瓦版本:6.2.0
  • cordova-android@5.1.1
  • 最新的Android SDK
  • Node version: v4.4.3
  • Cordova version: 6.2.0
  • cordova-android@5.1.1
  • Android SDK up to date

我确实在config.xml中设置了以下设置:

I did set these settings in the config.xml:

<allow-navigation href="*" />
<access origin="*" />
<allow-intent href="*" />

我正在使用白名单插件:

I am using the whitelist plugin:

<plugin name="cordova-plugin-whitelist" spec="1" />

我还在index.html文件中设置了此meta:

I also set this meta in the index.html file:

<meta http-equiv="Content-Security-Policy" content="default-src *; img-src 'self' data:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

我还没有设置其他的Cordova设置吗?

Is there other Cordova settings I forgot to set?

仅供参考,我已经删除了Android平台并将其重新添加到我的项目中,更新了所有插件,但仍然遇到相同的Ajax错误.

FYI, I have removed and re-addd the Android platform to my project, updated all my plugins but I still get the same Ajax error.

请帮助.

推荐答案

出现了完全相同的问题. $ .ajax在调试版本上可以正常工作.发行版本失败,状态码为0. 问题是一个星期的SSL证书.我将https更改为http,然后它也可以在发行版中使用.参见:

Had exactly the same problem. $.ajax works fine on debug version. Release Version fails with status code 0. Issue was a week SSL certificate. I changed the https to http and then it worked in release too. See:

https://论坛. ionicframework.com/t/cordova-plugin-whitelist-problem-only-in-release/43705/3

这篇关于在发布模式下运行Android Cordova应用程序时,Ajax调用失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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