2017-03-15 82 views
0

当我提交使用邮递员注册表单它工作正常,但是当我尝试使用下面的代码提交它显示一些错误,即时通讯无法弄清楚,任何人都请帮助我?错误时发射帖子请求

.controller('RegisterCtrl', function($scope, AuthService, $state, $http) { 
    $scope.user = { 
    name: '', 
    mobile:'', 
    email:'', 
    password:'' 
    }; 

    $scope.signup = function() { 
    $http.post("http://localhost:8080/api/signup", $scope.user, {headers: {'Content-Type': 'application/json'} }) 
     .then(function (response) { 
      return response; 
     }); 
    }; 
}) 

当我检查Chrome浏览器就会记录下面的错误:

angular.js:14362 Error: Unexpected request: POST http://localhost:8080/api/signup 
No more request expected 
    at $httpBackend (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-mocks.js:1402:9) 
    at sendReq (http://localhost:3000/bower_components/angular/angular.js:12178:9) 
    at serverRequest (http://localhost:3000/bower_components/angular/angular.js:11930:16) 
    at processQueue (http://localhost:3000/bower_components/angular/angular.js:16689:37) 
    at http://localhost:3000/bower_components/angular/angular.js:16733:27 
    at Scope.$eval (http://localhost:3000/bower_components/angular/angular.js:18017:28) 
    at Scope.$digest (http://localhost:3000/bower_components/angular/angular.js:17827:31) 
    at ChildScope.$apply (http://localhost:3000/bower_components/angular/angular.js:18125:24) 
    at HTMLInputElement.<anonymous> (http://localhost:3000/bower_components/angular/angular.js:26813:23) 
    at HTMLInputElement.dispatch (http://localhost:3000/bower_components/jquery/dist/jquery.js:4435:9) Possibly unhandled rejection: {}(anonymous function) @ angular.js:14362(anonymous function) @ angular.js:10859processChecks @ angular.js:16715$eval @ angular.js:18017$digest @ angular.js:17827$apply @ angular.js:18125(anonymous function) @ angular.js:26813dispatch @ jquery.js:4435elemData.handle @ jquery.js:4121 
+0

什么是错误你有?您可以在错误回调函数 – Lotus91

+0

中记录错误,但在不知道错误是什么的情况下无法知道您的问题是什么,但是您可能会遇到的这类代码最常见的问题之一就是CORS。也许这会有所帮助? http://stackoverflow.com/questions/17756550/angularjs-cors-issues – Claies

+0

你有没有试过像这样'JSON.stringify($ scope.user)'发送你的数据? – Lotus91

回答

0

前面已经指出的那样,你缺乏了很多重要的细节在你的描述。我最好的猜测是,你的终点期待您的用户对象被命名为“用户”,在这种情况下,您的电话后应该看起来更像是以下几点:

$http.post(
    "http://localhost:8080/api/signup", 
    { user: $scope.user }, 
); 
+0

我试过这个,但没有工作相同的错误。 – Inayath