连接拒绝我想要提供详细信息的地方

时间:2016-09-16 06:47:44

标签: html angularjs mongodb web

我在MEAN堆栈上制作测试应用程序,每当我尝试更新数据库中有关字段的信息时,Google Chrome就会拒绝连接拒绝我发布内容的Url。

控制器代码:

(function() {
angular.module('TimeSuck')
.controller('EditProfileController',['Upload','$scope','$state', '$http', function(Upload, $scope, $state, $http) {
$scope.user = localStorage['Userdata'] || undefined

$scope.$watch(function(){
    return $scope.file
},function(){
    $scope.upload($scope.file);
});

$scope.upload = function(file) {
    if(file){
        Upload.upload({
            url:'api/profile/editPhoto',
            method: 'POST',
            data: {userId: $scope.user._id},
            file: file
        }).progress(function(event){
            console.log("Uploaded");
        }).success(function(data){

        }).error(function(error){
            console.log(error);
        })
    }
};

$scope.updateUsername = function() {
    var request = {
        userId: $scope.user[0]._id,
        username: $scope.username
    }
    $http.post('api/profile/updateUsername', request).success(function(){
        console.log("success");
    }).error(function(error){
        console.log(error);
    })
}

$scope.updateBio = function() {
    var request = {
       userId: $scope.user[0]._id,
       bio: $scope.bio
    }

    $http.post('api/profile/updateBio', request).success(function(){
        console.log("success");
    }).error(function(error){
        console.log(error);
    });
}

$scope.post = function() {
    console.log("successfully Posted.");
}

并且html的代码在这里:

<div class="jumbotron">

<div class="col-sm-8 col-sm-offset-2">

<div class="row">   <div class="button" ngf-select ng-model="file" name="file" ngf-pattern="'image/*'"
ngf-accept="'image/*'" >Select</div> </div>

<div class="row">
<input class="form-control" ng-model="username" ng-blur="updateUsername()">

</div>

<div class="row">
<textarea class="form-control" ng-model="Bio" ng-blur="updateBio()"> </textarea>
<button type="submit" ng-click="post()"> Post </button>

</div>
</div>
</div>

0 个答案:

没有答案