Skip to content

Commit

Permalink
using .post.then
Browse files Browse the repository at this point in the history
  • Loading branch information
survivaltravel committed Apr 21, 2016
1 parent dc68ee9 commit 5aace52
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,39 @@ angular.module('starter.controllers', [])
var req = {
method: 'POST',
url: baseURL,
data: postObject,
//timeout: 5000
data: postObject
};

// $timeout(function() {
// deferred.resolve(); // this aborts the request!
// }, 5000);

// code change
$http.post(baseURL, postObject).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available

console.log('Success', response);
// resp.data contains the result

/*
//window.localStorage['username'] = resp.user.username;
window.localStorage['username'] = "theusername";
//clear form
$scope.data.username = "";
$scope.data.password = "";
*/
// go to dashboard page on success
$state.go('app.dashboard');

}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.error('ERROR', response);
});

/* ORIGINAL
$http(req).success(function(resp) {
console.log('Success', resp);
// resp.data contains the result
Expand Down Expand Up @@ -135,6 +160,9 @@ angular.module('starter.controllers', [])
}
})
*/


}


Expand Down

0 comments on commit 5aace52

Please sign in to comment.