【发布时间】:2019-12-16 12:22:47
【问题描述】:
在我的 cordova 应用程序中,我使用 $.ajax 请求来访问外部 api(在我的服务器上)。 我已经安装了cordova-plugin-whitelist。
但每次运行干净安装的应用程序或清理缓存 + 数据后,我都会收到以下错误之一:
1:当我启用 header('Access-Control-Allow-Origin: *');
Access to XMLHttpRequest at 'https://myapi_adress' from origin 'file://' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
2:禁用
Access to XMLHttpRequest at 'https://myapi_adress' from origin 'file://' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
在设备上重新启动应用程序后,一切运行完美。 来自设备的每个请求都包含
'Origin' => 'file://'
标题
但它只会在第一次运行或清除应用程序的缓存和数据后阻塞。
看起来白名单插件在首次运行或清除缓存后没有应用/工作。
有什么建议吗?
【问题讨论】:
-
你在等待 deviceReady() 事件吗?
-
@MaheswaranRavisankar ,当然,我已经找到答案并将发布它
标签: android ajax cordova cors cordova-plugins