简体   繁体   English

在Angular js中使用定制服务发布请求后出现内部服务器错误

[英]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.

相关问题 使用 React JS 和 Laravel 将带有图像文件的 POST 请求发送到数据库时出现内部服务器错误 - Getting Internal Server Error when sending POST request with an image file to database using React JS and Laravel 500(内部服务器错误)使用 Bottle Python 和 Angular JS - 500 (Internal Server Error) Using Bottle Python and Angular JS Angular JS路由,500个内部服务器错误 - Angular js Routes, 500 internal server error Larave Vue 发布请求返回 500 内部服务器错误 - Larave Vue post request return 500 internal server error Laravel AJAX POST请求失败(500内部服务器错误 - Laravel AJAX POST Request failing (500 Internal Server Error NetworkError:Ajax $ post请求中出现500个内部服务器错误 - NetworkError: 500 Internal Server Error in Ajax $post request 发出发布请求时的Laravel 5 Ajax 500(内部服务器错误) - Laravel 5 Ajax 500 (Internal Server Error) when making a post request jQuery - AJAX POST 请求给出 500 内部服务器错误 - jQuery - AJAX POST Request is giving a 500 Internal Server Error 使用angular js和REST Web服务的PUT错误400错误请求 - PUT Error 400 bad request using angular js and REST web services 节点JS Nodemailer POST内部服务器错误500 - Node JS Nodemailer POST internal server error 500
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM