我一直在与Access-Allow-Control-Origin做斗争,我正在使用Divshot。在我的移动应用程序中,我正在显示WordPress帐户的帖子,当我在浏览器中测试我的应用程序时,我可以看到这些帖子,但是一旦我在Chrome中打开应用程序,我就无法看到这些帖子。根据我所看到的,有一些人有同样的问题,所以我需要使用的配置文件中的CORS。
在他们是这么说的页面中,但是我不知道如何在我的应用程序中实现
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"
}
}
}但我还是没有什么好结果。
发布于 2015-05-18 02:57:18
如果有人想知道,在执行请求时,您必须发送更多的param,看看这个例子,我现在让它起作用了。
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');
});
}https://stackoverflow.com/questions/30291963
复制相似问题