你能告诉我哪里出了问题吗?有什么遗漏的东西我必须添加才能从heroku网站获取json
配置.ru
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
use Rack::Cors do
allow do
origins 'localhost:3000', '127.0.0.1:3000', 'http://stark-anchorage-86169.herokuapp.com/ages/ getfortest', /\Ahttp:\/\/192\.168\.0\.\d{1,3}(:\d+)?\z/
resource '/file/list_all/', :headers => 'x-domain-token'
resource '/file/at/*',
:methods => [:get, :post, :delete, :put, :patch, :options, :head],
:headers => 'x-domain-token',
:expose => ['Some-Custom-Response-Header'],
:max_age => 600
end
allow do
origins '*'
resource '/public/*', :headers => :any, :methods => :get
end
end
配置/应用程序.rb
Bundler.require(*Rails.groups)
module AppV11
class Application < Rails::Applications.
config.active_record.raise_in_transactional_callbacks = true
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
end
end
end
我的控制器看起来像这样,下面有一些助手
before_filter :set_access_control_headers
def set_access_control_headers
headers['Access-Control-Allow-Origin'] = 'http://staranchorage- 86169.herokuapp.com/ages/getfortest'
end
Angularjs 部分:
function getpost()
{
console.log("INSIDE GETPOST");
$http.get('http://stark-anchorage-86169.herokuapp.com/ages/getfortest')
.success(function(response)
{
console.log("INSIDE RESPONSE "+ response);
$scope.demogetpost = response.data;
console.log( $scope.demogetpost);
console.log("NOT PRINTING");
})
return $scope.demogetpost;
}