Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

Here is my controller. When I want to post some data to backend, I get error.

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

The error I get :

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)

NOTE: I have already used this controller code in other project, but it works fine.

share|improve this question
1  
'Unexpected request' - it looks like you suddenly included ngMock module (or other module for testing) – STEVER Sep 11 at 10:17
    
@STEVER yes, exactly. In app.js I included ngMockE2E. That's why it works in other porjects. What should I do? – vahid najafi Sep 11 at 10:24
    
@STEVER I cleaned ngMockE2E and testing part and now it works perfect. If you post the answer, I would accept it as an accepted answer. Thanks. – vahid najafi Sep 11 at 10:36
    
welcome :) posted the answer – STEVER Sep 11 at 10:44

2 Answers 2

up vote 2 down vote accepted

The problem is with "ngMockE2E" AngularJS module that should be used only for tests and not included like dependency for you project.

So solution: just remove this dependancy.

share|improve this answer

You have to describe $httpbackend.whenPOST in your app.js

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.