2017-03-15 104 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