【发布时间】:2023-03-15 09:43:01
【问题描述】:
我正在创建一个离子应用程序,它使用 $http get 从远程服务器获取 json 值。当我在浏览器上运行它而不是在真正的 Android 设备上运行它时,它会显示数据。我也已经安装了cordova-plugin-whitelist。
这是我在index.html上的代码
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
</head>
<body ng-app="starter">
<ion-nav-view>
</ion-nav-view>
</body>
</html>
controller.js
.controller('ProductsCtrl', function($scope, $ionicModal, $timeout, $http, $stateParams) {
console.log("ProductCtrl: prod_id = " + $stateParams.prod_id);
$scope.host = "xxxx";
$http.get("http://"+ $scope.host +"/xxxx/xxxx.php?cat_id=" + $stateParams.prod_id)
.then(function(response) {
$scope.products = response.data;
})
.error(function(data, status, headers,config){
console.log('data error');
})
.then(function(result){
things = result.data;
});
})
config.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.xxxxxxx" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>XXXX</name>
<description>
An Ionic Framework and Cordova project.
</description>
<author email="you@example.com" href="http://example.com/">
Your Name Here
</author>
<content src="index.html"/>
<access origin="*"/>
<preference name="webviewbounce" value="false"/>
<preference name="UIWebViewBounce" value="false"/>
<preference name="DisallowOverscroll" value="true"/>
<preference name="SplashScreenDelay" value="2000"/>
<preference name="FadeSplashScreenDuration" value="2000"/>
<preference name="android-minSdkVersion" value="16"/>
<preference name="BackupWebStorage" value="none"/>
<feature name="StatusBar">
<param name="ios-package" value="CDVStatusBar" onload="true"/>
</feature>
<allow-navigation href="http://xxxx.com/*" />
</widget>
正如您在index.html 中看到的那样,我已经按照我在here 看到的其他帖子中的建议放置了<meta> 标签
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
我也尝试卸载并重新安装cordova-plugin-whitelist,但没有任何改变。
cordova plugin remove cordova-plugin-whitelist
cordova plugin add cordova-plugin-whitelist
这些是控制台上显示的错误。大多数只是这样的404:
Failed to load resource: net::ERR_NAME_NOT_RESOLVED
但是这个可能是因为<meta>..
Refused to load the script 'http://localhost:35729/livereload.js?snipver=1' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval'".
(anonymous function) @ localhost:8100/?ionicplatform=ios:98
请帮忙..提前谢谢..
【问题讨论】:
-
您遇到任何错误??如果您发布您遇到的错误会很好
-
除此之外其他错误只有404。
-
拒绝加载脚本“localhost:35729/livereload.js?snipver=1”,因为它违反了以下内容安全策略指令:“script-src 'self' 'unsafe-inline' 'unsafe-eval'”。
-
另一件事,我的科尔多瓦版本是 6.5.0,我试图将其降级到 6.3.0。什么也没发生。
-
你可以在 naresh.k.suruvu@gmail.com 联系我,我会在那里讨论
标签: android angularjs cordova ionic-framework