[英]Internal Server error on post Request Using Made Custom Services in Angular js
i am new one for angular so i tried my best to solve this but after too much struggle i can't that's why asking. 我是有角度的新手,所以我尽力解决了这个问题,但是经过太多的努力,我才不能问这个。 actually, i am not getting response back using
$http
i don't why because according to me it's seems right. 实际上,我没有使用
$http
来获得响应,所以我不这样做,因为对我而言,这似乎是正确的。
Two Questions For This Problem 1- Post Request Fail 2- How CookieStore In angular 此问题的两个问题1-请求失败2-CookieStore的角度如何
signUpController.js signUpController.js
app.controller('signUpController', function ($rootScope, $scope, signUpService, $location) {
$scope.addUser = function(){
var user = {
"email": $scope.EmailInfo,
"confirm_email": $scope.ConfirmEmailInfo,
"password": $scope.PasswordInfo,
"confirm_password": $scope.ConfirmPasswordInfo,
"first_name": $scope.FirstnameInfo,
"last_name": $scope.LastNameInfo,
"dob": $scope.dateOfBirth,
"gender": $scope.radioValue
}
signUpService.addNewUser(user).then(function(response) {
if(response.status == 500) {
$rootScope.loggedIn = false;
$location.url('/SignUp');
}else {
$rootScope.loggedIn = true;
$location.url('/Stores');
console.log(data);
}
console.log(response);
});
}
});
signUpService.js signUpService.js
app.factory('signUpService', function($http, $cookieStore) {
var signUpServices = {
addNewUser : function(user) {
var promise = $http({
method:'POST',
url: "/user/register?account_id=" + utils.urlParam('account_id') ,
data: user
}).then(function(response) {
$cookieStore.put("token", response["token"]); // is it write that i used also check please
console.log(response.data);
return response.data;
},
function(reason) {
alert("There was a problem");
});
return promise;
}
};
return signUpServices;
});
error 错误
POST http://localhost:3000/user/register?account_id=0 500 (Internal Server Error) angular.js:10159
(anonymous function) angular.js:10159
sendReq angular.js:9980
$http.serverRequest angular.js:9757
deferred.promise.then.wrappedCallback angular.js:7303
deferred.promise.then.wrappedCallback angular.js:7303
(anonymous function) angular.js:7340
Scope.$eval angular.js:8685
Scope.$digest angular.js:8548
Scope.$apply angular.js:8771
(anonymous function) angular.js:13970
f.event.dispatch jquery.js:3
h.handle.i
Updated But Same Issue 更新但相同的问题
app.factory('signUpService', function($http) {
var signUpServices = {
addNewUser : function(user) {
var promise = $http({method: 'POST', url: "/user/register?account_id=" + utils.urlParam('account_id'),
data: user}).
success(function(data, status, headers, config) {
console.log("response");
alert(data);
}).
error(function(data, status, headers, config) {
alert(status);
});
return promise;
}
};
return signUpServices;
});
i will be really grateful to you if someone rectify this where need to required changes. 如果有人在需要更改的地方纠正了这个问题,我将非常感谢您。
You are using $http wrong 您使用的$ http错误
$http({method: 'GET', url: '/someUrl'}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
Here is how you can get cookie on each request: 这是您如何在每个请求上获取Cookie的方法:
$http.defaults.transformRequest.push(function (data) {
data.csrfToken = $browser.cookies().csrfToken;
return angular.toJson(data);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.