【发布时间】:2014-11-15 15:33:45
【问题描述】:
这是我的 HTML 表单
<form class="navbar-form navbar-right" ng-submit="loginuser()">
<input type="email" ng-model="user.username" placeholder="Email" class="form-control" required>
<input type="password" ng-model="user.password" placeholder="Password" class="form-control" required>
<button class="btn btn-success" type="submit">Login</button>
</form>
我的 app.js 是
function navbarformcontroller($scope,$http){
$scope.user = {};
$scope.loginuser = function(){
console.log('entered');
$http({
method : 'POST' ,
url : 'http://localhost:3000/login',
data : $scope.user
})
.success(function(data){
alert(data);
})
.error(function(data, status){
alert(data + " " + status + 'x');
})
};
}
在我的服务器端是节点 js
router.get('/', function(req, res) {
req.render('login',{username : req.username, password : req.password});
res.send('success');
log(username + " " + password);
});
并且错误详情在客户端控制台是
XMLHttpRequest 无法加载
http://localhost:3000/login。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问 Origin 'http://localhost:63342'。
【问题讨论】:
-
不要在两个不同的端口上运行您的应用程序,否则您将成为SOP 的受害者...
标签: javascript node.js angularjs localhost