这是我的控制器。当我想将一些数据发布到后端时,我会得到错误。
.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)注意:我已经在其他项目中使用了这个控制器代码,但是它工作得很好。
发布于 2015-09-11 10:42:46
问题在于"ngMockE2E“AngularJS模块应该只用于测试,而不是像项目依赖一样包括在内。
因此,解决办法:只需消除这种依赖。
发布于 2015-11-22 19:40:19
您必须在您的$httpbackend.whenPOST中描述app.js
$httpBackend.whenPOST('http://cms.focusweb.ir/Json/get_article')`enter code here`
.respond(); https://stackoverflow.com/questions/32521015
复制相似问题