简体   繁体   English

Access-Control-Allow-Origin不允许在PhoneGap中使用ng-views获取Origin

[英]using ng-views in PhoneGap getting Origin is not allowed by Access-Control-Allow-Origin

I am trying to get ng-views to work in android phoneapp app. 我正在尝试让ng-views在android phoneapp应用程序中工作。 I get the following error when I trying to navigate to one of the views via hyperlink. 当我尝试通过超链接导航到其中一个视图时,出现以下错误。

"Origin is not allowed by Access-Control-Allow-Origin" “ Access-Control-Allow-Origin不允许使用起源”

I have tried modifying the the cordova,xml in the res folder with no luck. 我试过修改res文件夹中的cordova,xml,但是没有运气。

From

 <access origin="http://127.0.0.1*"/> <!-- allow local pages -->

To

<access origin="*"/>

Any advice is appreciated, below is the code. 任何建议表示赞赏,下面是代码。

Thanks. 谢谢。

HTML: HTML:

<html ng-app="AngApp">
  <head>
    <meta name="viewport" content="width=320; user-scalable=no" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>Minimal AppLaud App</title>

      <script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>
      <script type="text/javascript" charset="utf-8" src="angular.js"></script>
      <script type="text/javascript" charset="utf-8" src="app.js"></script>
      <script type="text/javascript" charset="utf-8">

        var onDeviceReady = function() {

           $.support.cors = true;
           $.mobile.allowCrossDomainPages = true;

           // The message from the service is appearing, so Angular seems 
           // to be working fine without having to bootstrap it.
           //angular.bootstrap(document, ['AngApp']);
        };

        function init() {
            document.addEventListener("deviceready", onDeviceReady, true);
        }   
</script>  

  </head>
  <body onload="init();" id="stage" class="theme">
    <h2>Angular App</h2><br/>
    <a href="#/">View1</a>
    <a href="#/view">View2</a>
    <hr/>
    <div data-ng-controller="MainCtrl">    
        <p>{{Message}}</p>    

        <input type="text" data-ng-model="Message"/>

    </div>
    <hr/>

    <div data-ng-view></div>


  </body>
</html>

APP.JS: APP.JS:

var angApp = angular.module('AngApp',[]);

angApp.config(function ($compileProvider){
    $compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);
});

angApp.config(function ($routeProvider) {

    $routeProvider
    .when('/', {
        controller: TestCtrl1,
        templateUrl: 'view1.html'
    })
    .when('/view', {
        controller: TestCtrl2,
        templateUrl: 'view2.html'
    });
});


angApp.factory('myService',function(){

    return 'I am a service';

});

function MainCtrl($scope, myService){

    $scope.Message = 'This is the main controller. '+ myService;
}

function TestCtrl1($scope){

    $scope.Message = 'This is controller 1.';
}

function TestCtrl2($scope){

    $scope.Message = 'This is controller 2.';
}

您在href =“#/ view”中缺少一个#号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 webview-访问控制允许原点不允许原点(使用cordova将angular转换为mobile) - webview - origin is not allowed by access-control-allow-origin (convert angular to mobile using cordova) Android webview - XMLHttpRequest无法加载Origin <url> Access-Control-Allow-Origin不允许使用 - Android webview - XMLHttpRequest cannot load Origin <url> is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin不允许使用Origin null(从android获取XML) - Origin null is not allowed by Access-Control-Allow-Origin (get XML from android) 科尔多瓦没有访问控制允许来源 - cordova No Access-Control-Allow-Origin android webview - 访问控制允许来源 - android webview - Access-Control-Allow-Origin Angular 无“访问控制允许来源” - Angular No 'Access-Control-Allow-Origin' Phonegap / Cordova App在Jelly Bean中断 - Access-Control-Allow-Origin和setAllowUniversalAccessFromFileURLs - Phonegap/Cordova App breaks in Jelly Bean - Access-Control-Allow-Origin and setAllowUniversalAccessFromFileURLs JSON_2_Region.json。 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问原始“空”。 - JSON_2_Region.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. ionic:请求的资源上不存在“ Access-Control-Allow-Origin”标头 - ionic: No 'Access-Control-Allow-Origin' header is present on the requested resource Android 4.1上的Access-Control-Allow-Origin错误 - Access-Control-Allow-Origin Error At Android 4.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM