這裏是我的HTML表單如何檢索NODE JS從POST數據
<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]的受害者(https://en.wikipedia.org/wiki/Same-origin_policy)... – Bergi 2014-09-21 16:03:21