升级到 Cordova 5.0 + cordova-android@4.0 后 Ajax 请求失败 [英] Ajax requests fail after upgrading to Cordova 5.0 + cordova-android@4.0

查看:31
本文介绍了升级到 Cordova 5.0 + cordova-android@4.0 后 Ajax 请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级到 Cordova 5.0(和 Cordova Android 4.0),从那时起,我的应用无法再访问外部资源.

I recently upgraded to Cordova 5.0 (and Cordova Android 4.0) and, since then, my app can no longer access external resources.

我在 config.xml 中仍然有 <access origin="*"/>(和以前一样),而且我还有 <uses-permission android:name="android.permission.INTERNET"/> 在 AndroidManifest.xml 中(和以前一样),但是 ajax 调用被拒绝,没有任何解释(textStatus"参数是错误",errorThrown"参数是空的,并且xhr.state() 返回拒绝").

I still have <access origin="*" /> in config.xml (as before), and I still have <uses-permission android:name="android.permission.INTERNET" /> in AndroidManifest.xml (as before), but ajax calls are rejected with no explanation (the "textStatus" param is "error", the "errorThrown" param is null, and xhr.state() returns "rejected").

我已经确认没有请求正在访问服务器,因此它似乎被 Android 阻止,但日志没有给出任何解释为什么...

I've verified that no request is hitting the server, so it appears it is being stopped by Android, but the log doesn't give any explanation as to why...

我可以从 Android 浏览器正常访问相关 URL,但不能从应用程序访问.

I can access the URL in question fine from the Android browser, just not from the app.

ajax 请求是通过调用 Backbone.js 的 Backbone.sync() 发出的,它最终调用 jquery 的 $.ajax().我没有改变任何关于如何拨打电话的事情......只是升级了cordova.

The ajax request is made via a call to Backbone.sync() of Backbone.js, which ultimately calls jquery's $.ajax(). I haven't changed anything about how the call is made... just upgraded cordova.

Cordova 5.0 中是否有针对网络请求的新要求​​/设置,或者我需要做的与以前的 Cordova 版本不同的任何事情?

有谁知道我可以通过什么方式获得更多关于为什么 Android 和/或 Cordova 拒绝请求的信息?

Does anyone know of a way I can get more information as to why Android and/or Cordova is rejecting the request?

推荐答案

我找到了 android@4.0.0cordova 平台的罪魁祸首.它现在需要新的 cordova-plugin-whitelist 插件.

I tracked the culprit down to the android@4.0.0 cordova platform. It now requires the new cordova-plugin-whitelist plugin.

它可以用

cordova plugin add cordova-plugin-whitelist

或通过添加

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

到config.xml,然后用

to config.xml, and then it is configured with

<allow-navigation href="*" />

代替旧的 标签.

当出现这样的问题时,日志不再吐出白名单拒绝"错误消息有点烦人(这本来可以为我节省大量时间),但也许以后会出现.

It's a little annoying that the log doesn't spit out the "whitelist rejection" error messages anymore when a problem like this comes up (that would have saved me a ton a time), but maybe that'll come later.

这篇关于升级到 Cordova 5.0 + cordova-android@4.0 后 Ajax 请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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