Advertisement
Guest User

Angular $http json params transformReq no jQuery

a guest
Apr 9th, 2014
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var loginObj = {
  2.   'username':   $scope.username,
  3.   'password':   $scope.password,
  4.   'grant_type': 'password',
  5.   'client_id':  'web'
  6. }
  7.  
  8. var doLogin = $http({
  9.   method: 'POST',
  10.   url: 'https://api/v1/token',
  11.   headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  12.   transformRequest: function(obj) {
  13.     var str = [];
  14.     for(var p in obj) {
  15.       str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
  16.     }
  17.     return str.join('&');
  18.   },
  19.   data: loginObj,
  20.   responseType: 'json'
  21. })
  22.  
  23. doLogin.then(
  24.   onLoginSuccess,
  25.   onLoginError
  26. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement