[英]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.