【发布时间】:2015-09-11 10:14:18
【问题描述】:
这是我的控制器。当我想将一些数据发布到后端时,我得到了错误。
.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)
注意:我已经在其他项目中使用过这个控制器代码,但它工作正常。
【问题讨论】:
-
'Unexpected request' - 看起来你突然包含了 ngMock 模块(或其他用于测试的模块)
-
@STEVER 是的,完全正确。在
app.js中,我包含了ngMockE2E。这就是它在其他项目中工作的原因。我该怎么办? -
@STEVER 我清理了
ngMockE2E并测试了部分,现在它可以完美运行了。如果您发布答案,我会接受它作为已接受的答案。谢谢。 -
欢迎 :) 发布答案
标签: javascript angularjs http-post httpservice