Cordova应用程序在Android设备上运行时无法进行Ajax调用 [英] Cordova app fails to make ajax calls while running on android device
问题描述
< meta http-equiv ="Content-Security-Policy" content ="default-src'self'* .xyz.com data:gap:* .xyz.com'unsafe-eval'; style-src'self''unsafe-inline'; media-src *; connect-src *>
< meta http-equiv="Content-Security-Policy" content="default-src 'self' *.xyz.com data: gap: *.xyz.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *;connect-src *">
在设备中运行时我在Visual Studio 2015中收到的错误消息是:无法加载XYZ.COM,但该应用程序在涟漪图浏览器上正常工作.
error message that I am getting in visual studio 2015 when running in device is : FAILED TO LOAD RESOURE XYZ.COM but the app works fine on ripple browser.
问题与csp有关吗?如果可以,我该如何解决?
is the issue related to csp? if so how may I fix it?
推荐答案
嗨阿努普,
通过您发布的元标记.已在CSP中启用Ajax调用(通过指令"connect-src *").
through the meta tag you posted. The Ajax call has been enabled in CSP (through directive "connect-src *").
请首先检查XYZ.COM是否有效.如果要从远程主机加载资源,请尝试将http/https模式添加到meta标签指令中.例如:
Please first check if XYZ.COM is valid. And try adding the http/https schema to the meta tag directive if you are loading resource from a remote host. ex:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' http://*.xyz.com ";...>
如果上述方法均无效,则如果您有cordova-plugin-whitelist,建议您将以下代码添加到root元素下的config.xml中:
If none of the above works, If you are having cordova-plugin-whitelist, I would suggest you adding the following codes to config.xml under root element:
<access origin="http://*.XYZ.com" />
<允许意图的href ="http://*.XYZ.com"; />
<allow-intent href="http://*.XYZ.com" />
< allow-navigation href =" http://*.XYZ.com"//>
<allow-navigation href="http://*.XYZ.com"/>
如果仍然没有任何效果,您能否分享一个可以重现此问题的基本演示?
If still nothing works, Could you share a basic demo that can reproduce this problem?
这篇关于Cordova应用程序在Android设备上运行时无法进行Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!