首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在DIVSHOT上启用CORS?

如何在DIVSHOT上启用CORS?
EN

Stack Overflow用户
提问于 2015-05-17 20:46:00
回答 1查看 102关注 0票数 0

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

他们是这么说的页面中,但是我不知道如何在我的应用程序中实现

代码语言:javascript
复制
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.

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

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

但我还是没有什么好结果。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-18 02:57:18

如果有人想知道,在执行请求时,您必须发送更多的param,看看这个例子,我现在让它起作用了。

代码语言:javascript
复制
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');
  });
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30291963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档