我是新手到角js。在這裏,我試圖從「rails」服務器調用API「http://localhost:3000/」。我得到了錯誤發送獲取請求的角度來源http:// localhost:3000
迴應預檢要求未通過訪問控制檢查:沒有 「訪問控制允許來源」
我加入「CORS」瀏覽器擴展程序來解決它。現在問題是我的請求傳遞給localhost:3000作爲[選項],並且我想要它作爲獲取請求。
'use strict';
angular.module('dayton')
.service('foodCategoryService', ['$http', '$window', 'authService', 'Upload',
function($http, $window, authService, Upload){
var field = {};
field.getFields = function(){
console.log("---------foodCategoryService")
return $http.get('http://localhost:3000/api/list_food_category', {
headers: {Authorization: authService.getToken()}
})
.then(function(response) {
return response;
}, function(x) {
$scope.authError = 'Server Error';
});
};
return field;
}]);
的ActionController :: RoutingError(無路由匹配[OPTIONS] 「/ API/list_food_category」):
任何幫助將被讚賞
CORS插件只能解決它。您的服務器需要允許CORS請求。 – Ved
如果您在同一臺主機上調用和託管前端,您不需要CORS擴展,即'localhost'? –
不,我在這裏使用兩臺不同的服務器。 http:// localhost:8081 /是我當前的服務器,我正嘗試將api調用發送到http:// localhost:3000/ – user100693