【发布时间】:2015-03-14 16:24:04
【问题描述】:
我在 Node js 中运行我的前端,在 Jetty 中运行后端。我正在尝试使用 Angular JS 从前端发布数据,但它对我不起作用。谁能建议可能是什么问题? 节点 Js 运行在 3000 端口,码头运行在 9011。 这是代码sn-p:
var app = angular.module("loginapp", []);
app.controller("loginctrl", function($scope,$http) {
app.config(['$sceDelegateProvider', function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist(['self', 'http://localhost:9011/**']);
}]);
$scope.login = function(e){
console.log('clicked login...');
e.preventDefault();
$http({
url: "http://localhost:9011/test/dummy/doStuff1",
method: "POST",
data : {username: $scope.userName, password: $scope.password},
headers: { 'Content-Type': 'application/json' },
withCredentials: false,
}).success(function (data, status, headers, config) {
console.log('status',status);
console.log('data',status);
console.log('headers',status);
});
}
});
在浏览器控制台中显示:
POST http://localhost:9011/test/dummy/doStuff1
(index):1 XMLHttpRequest cannot load http://localhost:9011/test/dummy/doStuff1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 500.
我不确定是什么导致了问题,有人可以帮我解决这个问题吗?
【问题讨论】:
-
什么不起作用?你能指定吗?
-
POST 无法调用后端模块。我不确定是什么导致了问题。请您帮我确定原因。
标签: angularjs node.js express http-post angular-ui