title: Send login data to the server using AngularJS/Ionic
body: <p>I'm trying to send the existing user data on the server with the <code>$http</code>-service of angularjs. The user data, so (<code>loginData</code>), are created and existing on the backend server. With the information of the user I would like to log in on my mobil phone. How can I compare local entered data with the existing data on the server? My code doesn't work yet. </p>
  
  <p><strong>the loginService:</strong></p>
  
  <pre><code>myApp.factory('loginService', function($http){
    var endPoint = "https://www.****.***/****/****";
    var loginData =
    {
      "username": "user",
      "password": "pass"
    };
  
    return{
      login: function(username, password){
        return $http.post(endPoint, loginData);
      }
    }
  });
  </code></pre>
  
  <p><strong>the loginController:</strong></p>
  
  <pre><code>myApp.controller('LoginCtrl', function ($scope, $location, $window, loginService) {
  
    $scope.logIn = function logIn(username, password) {
      if (username !== undefined &amp;&amp; password !== undefined) {
  
        loginService.login(username, password).success(function(data) {
          $window.sessionStorage.token = data.token;
          $window.location.href = '/index.html';
        }).error(function(status, data) {
          console.log(status);
          console.log(data);
        });
      }
    }
  })
  </code></pre>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;ion-content style="text-align: left" ng-controller="LoginCtrl"&gt;
      &lt;label class="item item-input"&gt;
        &lt;span class="input-label"&gt;Name:&lt;/span&gt;
        &lt;input name="name" autofocus="true" required="true" type="text"
               ng-model="username"/&gt;
      &lt;/label&gt;
      &lt;label class="item item-input"&gt;
        &lt;span class="input-label"&gt;Password:&lt;/span&gt;
        &lt;input name="password" required="true" type="password"
               ng-model="password"/&gt;
      &lt;/label&gt;
      &lt;button id="button-1" class="button button-block button-positive" ng-click="logIn(username, password)"&gt;
        Login
      &lt;/button&gt;
  &lt;/ion-content&gt;
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Error: Unexpected request: POST https://www.****.***/****/****
  No more request expected
      at $httpBackend (angular-mocks.js:1244)
      at n (ionic.bundle.min.js:119)
      at f (ionic.bundle.min.js:117)
      at ionic.bundle.min.js:151
      at n.$eval (ionic.bundle.min.js:165)
      at n.$digest (ionic.bundle.min.js:163)
      at n.$apply (ionic.bundle.min.js:166)
      at HTMLButtonElement.&lt;anonymous&gt; (ionic.bundle.min.js:446)
      at HTMLButtonElement.Gf.c (ionic.bundle.min.js:66)
      at n (ionic.bundle.min.js:22)(anonymous function) @ ionic.bundle.min.js:139(anonymous function) @ ionic.bundle.min.js:111(anonymous function) @ ionic.bundle.min.js:151n.$eval @ ionic.bundle.min.js:165n.$digest @ ionic.bundle.min.js:163n.$apply @ ionic.bundle.min.js:166(anonymous function) @ ionic.bundle.min.js:446Gf.c @ ionic.bundle.min.js:66n @ ionic.bundle.min.js:22t @ ionic.bundle.min.js:22l @ ionic.bundle.min.js:22
  
  loginController.js:13 undefined
  </code></pre>
  
  <p>I still don't get the <strong>HTTP status code 200</strong>. What is wrong with the code?</p>
  
  <p>many thanks</p>