我上應用,在那裏我使用Hapijs /的NodeJS與AngularJS爲什麼要返回未定義?
在這裏工作是的NodeJS部分
server.route({
method: 'POST',
path: '/login',
handler: function(request, reply) {
USER: request.payload.user,
PWD: request.payload.password,
PLANTA: request.payload.planta,
PLANGROUP: request.payload.plantgroup,
START_DATE: request.payload.startDate
}
});
現在角部位
.factory('LoginService', function($http, $q) {
var defer = $q.defer();
return {
login: function() {
$http.post('http://localhost:8000/login', {
user: 'USRCP_HW',
password: 'usrcp2012',
planta: '6000',
plantroup: 'E10',
startDate: '2014-11-26'
}).success(function(data) {
console.log(data);
return data;
}).error(function(data, status){
console.log(data, status);
defer.reject(data);
});
return defer.promise;
}
}
});
和登錄控制器
.controller('LoginCtrl', function($rootScope, $scope, $stateParams, LoginService) {
$scope.login = function(data) {
console.log(data);
};
});
所有我需要的是日誌中的數據,但我GE未定義。
,並在控制器我做
$scope.login = function(data) {
console.log(data);
LoginService.login(data).then(function() {
console.log(data);
})
};
我得到這個在瀏覽器控制檯
OPTIONS http://localhost:8000/login
XMLHttpRequest cannot load http://localhost:8000/login . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://127.0.0.1:8000 ' is therefore not allowed access. The response had HTTP status code 501.
同時匹配的URL的建議,他們應該是本地主機:8000或127.0.0.1:8000 – Chandermani
避免[遞延反模式](http://stackoverflow.com/q/23803743/1048572)! – Bergi