【发布时间】:2015-10-07 08:29:00
【问题描述】:
我的应用程序是一个带有 $hhtp.get 请求的简单离子应用程序,在我的 Android 手机上的 PhoneGap Build 之后无法运行。当我调试它给我一个 404 错误。 当我使用 ionic serve -p $PORT 命令在笔记本电脑上运行它时,它给了我一个 CORS 错误。 如果我激活 CORS 插件,它确实可以在我的笔记本电脑上的 Chrome 中使用。 我在 c9 (cloud 9) 上编码并在 Adobe PhoneGap 上构建。
我的请求
.controller('teamCtrl', function($scope, $http, $window) {
$http.get("http://google.com")
.success(function(response) {
$scope.categories = getArray(response);
var b =1;
})
.error(function(response) {
$window.alert("d'oh!");
});
})
我在 index.html 中的 CSP:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
config.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.openorganix919048" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>OpenOrganix</name>
<description>
An Ionic Framework and Cordova project.
</description>
<author email="hi@ionicframework" href="http://ionicframework.com/">
Ionic Framework Team
</author>
<content src="index.html"/>
<access origin="*" />
<allow-navigation href="http://*/*" />
<allow-intent href="http://*/*"/>
<preference name="webviewbounce" value="false"/>
<preference name="UIWebViewBounce" value="false"/>
<preference name="DisallowOverscroll" value="true"/>
<preference name="android-minSdkVersion" value="16"/>
<preference name="BackupWebStorage" value="none"/>
<preference name="SplashScreen" value="screen"/>
<preference name="SplashScreenDelay" value="3000"/>
<feature name="StatusBar">
<param name="ios-package" value="CDVStatusBar" onload="true"/>
</feature>
<platform name="android">
<icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
<icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
<icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
<icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
<icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
<icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
<splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/>
<splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/>
<splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/>
<splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/>
<splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" density="land-xxhdpi"/>
<splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" density="land-xxxhdpi"/>
<splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
<splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
<splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
<splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
<splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
<splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
</platform>
</widget>
Cordova 白名单插件已安装。
我尝试使用拦截器添加以下标头:
<Access-Control-Allow-Origin : *>
我到处读到 Cordova Whitelist 应该解决这个问题...请帮助我!
【问题讨论】:
-
首先检查您是否在项目中安装了cordova-plugin-whitelist,方法是输入cmd as ionic plugin ls
-
@Marc,在你的 config.xml 中,你有什么
whitelist插件参考? -
嗨 Anil,这是插件列表...它存在:
com.ionic.keyboard 1.0.4 "Keyboard" cordova-plugin-console 1.0.1 "Console" cordova-plugin-device 1.0.1 "Device" cordova-plugin-splashscreen 2.1.0 "Splashscreen" cordova-plugin-whitelist 1.0.0 "Whitelist" -
@andre3wap,谢谢,但我不确定您所说的引用是什么意思。你能举个例子吗? - 我在顶部添加了整个 config.xml。
标签: android cordova xmlhttprequest ionic phonegap-build