如何在DIVSHOT上启用CORS?

时间:2015-05-17 20:46:01

标签: angularjs wordpress header cors divshot

我一直在与Access-Allow-Control-Origin挣扎,我正在使用Divshot。在我的移动应用程序中,我正在显示WordPress帐户的帖子,当我在浏览器中测试我的应用程序时,我可以看到帖子,但是一旦我在Chrome移动版中打开应用程序,我就无法看到这些帖子。根据我的看法,有些人有同样的问题,所以我需要在Divshot配置文件中使用CORS。

在Divshot页面this is what they say,但我不知道如何在我的应用中执行此操作

Custom Headers
If you need to set custom response headers for specific routes,
you can use the headers key in your configuration file:

{
  "headers": {
    "/cors-stuff/**": {
      "Access-Control-Allow-Origin": "*"
    },
    "/scripts/**": {
      "content-type": "text/javascript"
    }
  }
}

This can be useful for applying a content security policy, enforcing a different content-type, enabling cross-origin resource sharing (CORS), and more.

这就是我在配置文件中的内容

{
  "name": "urbanetradio",
  "root": "www",
  "clean_urls": true,
  "error_page": "error.html",
  "headers": {
    "Access-Control-Allow-Origin": "*",
    "/js/**": {
      "content-type": "text/javascript"
    }
  }
}

但我仍然没有任何好结果。

1 个答案:

答案 0 :(得分:0)

万一有人想知道,在做请求的时候你必须发送更多的参数,看看这个例子,我现在就开始工作

getBlogs: function($scope) {
  $scope.postsURL = 'http://urbanetradio.com/wp-json/posts?_jsonp=JSON_CALLBACK';
  $http.jsonp($scope.postsURL).success(function(data, status, headers, config) {
    console.log(config);
    $scope.posts = data;
  }).error(function(data, status_headers, config) {
      console.log('error');
  });
}