Rod Michael Coronel
Rod Michael Coronel

Reputation: 592

angular $http POST becomes a GET

I have the following angular service:

angular.module('app.services.api_login', [])
.factory('loginApi', function($http, $q, CONFIG) {
  return function(email, password) {
    var promise = $http({
      method: 'POST',
      url: CONFIG.login_url, 
      data: {
        username: email,
        password: password
      },
      headers: {'Content-Type': 'application/json'}
    }).
      then(function(response){
        if (typeof response.data === 'object') {
          return response;
        } else {
          return $q.reject(response);
        }
      }, function(error){
        return $q.reject(error);
      });

    return promise;
  }
});

In the controller, I am able to invoke the service. However, inspecting the Network requests made by the browser, it does an HTTP GET.

Any possible ideas why?

Upvotes: 0

Views: 313

Answers (2)

sparkpham
sparkpham

Reputation: 111

Remove the '/' at the end of your CONFIG.login_url

Upvotes: 1

hurricane
hurricane

Reputation: 6724

I am using this post method in angularjs.

$http.post('url', data).
              success(function(data, status, headers, config) {
                console.log(data);
            }).
              error(function(data, status, headers, config) {
                  alert("error");
            });

Upvotes: 0

Related Questions