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
什麼是錯誤你有?您可以在錯誤回調函數 – Lotus91
中記錄錯誤,但在不知道錯誤是什麼的情況下無法知道您的問題是什麼,但是您可能會遇到的這類代碼最常見的問題之一就是CORS。也許這會有所幫助? http://stackoverflow.com/questions/17756550/angularjs-cors-issues – Claies
你有沒有試過像這樣'JSON.stringify($ scope.user)'發送你的數據? – Lotus91