繁体   English   中英

离子中的AngularJS $ http发布错误

[英]Angularjs $http post error in Ionic

这是我的控制器。 当我想向后端发布一些数据时,出现错误。

.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)

注意:我已经在其他项目中使用了此控制器代码,但是工作正常。

问题在于“ ngMockE2E ” AngularJS模块仅应用于测试,不应像项目的依赖项那样包含在其中。

因此,解决方案:只需删除此依赖项即可。

您必须在app.js中描述$ httpbackend.whenPOST

$httpBackend.whenPOST('http://cms.focusweb.ir/Json/get_article')`enter code here`
    .respond(); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM