【问题标题】:Ionic App not able to submit get RequestIonic App 无法提交获取请求
【发布时间】:2015-05-29 19:36:26
【问题描述】:

我一直在努力向 google places api 提交一个简单的获取请求

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=xxxx

我不断收到错误消息: XMLHttpRequest 无法加载 https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8…ius=500&types=food&name=cruise&key=xxxx。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问 Origin '8100'。

我在网上查了这个,它与 CORS 有关,但我无法弄清楚任何事情。如果有人能指出我正确的方向,那就太好了。

谢谢

【问题讨论】:

    标签: ajax angularjs ionic-framework


    【解决方案1】:

    我能够使用 ionic 轻松地调用该网址。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" />
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <link href="components/lib/ionic/css/ionic.css" rel="stylesheet" />
        <script src="components/lib/ionic/js/ionic.bundle.js"></script>
        <script src="components/lib/ionic/js/angular/angular-resource.js"></script>
        <script type="text/javascript">
            angular.module('myApp',
    [
     'ionic',
     'ngResource'
    ])
    .factory('GetData', function ($resource)
    {
        return {
            getg: function ()
            {
                return $resource('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=xxxx', null).get();
            }
        }
    })
    .controller('SomeController', function (GetData)
    {
        GetData.getg().$promise.then(
            function (answer)
            {
                console.log(answer);
            });
    });
        </script>
    </head>
        <body ng-app="myApp" ng-controller="SomeController"></body>
    </html>
    

    【讨论】:

    【解决方案2】:

    对我有用的是安装这个插件:

    • cordova-plugin-whitelist

    控制台:

    cordova插件添加cordova-plugin-whitelist

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多