内部服务器错误在 post 请求中使用 Angular js 中的自定义服务
Internal Server error on post Request Using Made Custom Services in Angular js
我是 angular 的新人,所以我尽力解决这个问题,但经过太多的斗争,我不能这就是问的原因。 实际上,我没有收到回复 $http
我不知道为什么,因为据我说这似乎是正确的。
这个问题的两个问题 1-发布请求失败 2-饼干如何存放在角度中
注册控制器.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);
});
}
});
注册服务.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;
});
错误
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
已更新但相同的问题
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;
});
如果有人在需要更改的地方纠正此问题,我将不胜感激。
你用错$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.
});
以下是在每个请求上获取cookie的方法:
$http.defaults.transformRequest.push(function (data) {
data.csrfToken = $browser.cookies().csrfToken;
return angular.toJson(data);
});
相关文章:
- Angular JS IE9 Hashbang url rewriting
- Node.JS, Angular.JS, MySql,Express.JS
- spin.js/angular spinner:如何将spin定位到DOM元素中(包括plunker演示)
- JS/ANGULAR使用一个变量's值作为另一个对象的键
- 添加一个“;以及“;到String-js/Angular中的最后一个单词
- 未调用内部JS Angular Controller
- Angular html文件可以'找不到JS控制器[Node.JS/Angular]
- 尝试跨站点 JSON 使用 JS(Angular)请求 API
- 找不到Angular.js Angular拖放自定义回调函数
- 如何使用Node.js, Angular.js和Firebase实现无限滚动
- 过滤文件夹中的文件,并使用ng-repeat (JS, Angular)显示它们
- If - JS/Angular中变量的正则表达式(不区分大小写)
- JS-angular为什么使用“ng click=”;f()"`属性,而不是`$(el).on('cl
- 使用Node.js / Angular对Google电子表格JSON进行跨域请求
- 多个步骤来处理数据,这是JS/Angular的好模式
- Highstock.js / Angular.js中的范围选择器在xAxis配置字段存在时不会更新图表
- 永远运行一个Node.js Angular.js Gulp.js应用
- 如何在不显示API密钥的情况下使此代码正常工作?我正在Node.js/Angular/Express上构建应用程序
- 图表.js & Angular 2 - ng2-charts 自定义点击事件
- 将html模板解析为客户端JS.Angular + Browserify + Babel + ES2015 + Gulp