0
这是我的控制器。当我想将一些数据发布到后端时,出现错误。
.controller('LoginCtrl', function($http, $scope, $state, $ionicPopup, AuthService) {
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$http({
method: 'POST',
url: 'http://cms.focusweb.ir/Json/get_article',
data: { id: 25 },
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(response) {
// handle success things
console.log(response);
})
.error(function(data, status, headers, config) {
// handle error things
})
})
的错误我得到:
Error: Unexpected request: POST http://cms.focusweb.ir/Json/get_article
No more request expected
at $httpBackend (angular-mocks.js:1207)
at sendReq (ionic.bundle.js:19160)
at status.$get.serverRequest (ionic.bundle.js:18872)
at processQueue (ionic.bundle.js:23394)
at ionic.bundle.js:23410
at Scope.parent.$get.Scope.$eval (ionic.bundle.js:24673)
at Scope.parent.$get.Scope.$digest (ionic.bundle.js:24484)
at Scope.parent.$get.Scope.$apply (ionic.bundle.js:24778)
at done (ionic.bundle.js:19191)
at completeRequest (ionic.bundle.js:19363)
注:我已经使用在其他项目中该控制器的代码,但它工作正常。
“意外的请求” - 它看起来像你突然包含ngMock模块(或用于测试其他模块) –
@STEVER是的,没错。在'app.js'中我包含了'ngMockE2E'。这就是它在其他项目中的原因。我该怎么办? –
@STEVER我清理了'ngMockE2E'和测试部分,现在它工作得很完美。如果你发布答案,我会接受它作为接受的答案。谢谢。 –