Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .controller('CadastroUserCtrl', ['$scope', '$stateParams', '$http',
- function($scope, $stateParams, $http) {
- $scope.data = {};
- $scope.cadastrarUser = function(){
- var nome = $scope.data.nome;
- var email = $scope.data.email;
- var login = $scope.data.login;
- var senha = $scope.data.senha;
- var confirmSenha = $scope.data.confirmSenha;
- var userJson = {
- 'name': nome,
- 'email': email,
- 'username': login,
- 'password': senha,
- 'confirmPassword': confirmSenha
- };
- userJson = serializeData(userJson);
- $http.post('localhost:3000/registerdonor', {
- name: nome,
- email: email,
- username: login,
- password: senha,
- confirmPassword: confirmSenha
- })
- .success(function(response) {
- // authentication OK
- alert("Certo!");
- })
- .error(function(status) {
- // Error: authentication failed
- alert(status);
- });
- //$http.post('http://localhost:3000/registerdonor', userJson, 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8').success().error();
- //$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8de";
- /*$http({
- method: 'post',
- url: 'localhost:3000/registerdonor',
- params: userJson,
- headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'}
- }).success(function(status) {
- alert("Cadastrado!");
- }).error(function(status) {
- alert(status);
- });*/
- function serializeData( data ) {
- // If this is not an object, defer to native stringification.
- if ( ! angular.isObject( data ) ) {
- return( ( data == null ) ? "" : data.toString() );
- }
- var buffer = [];
- // Serialize each key in the object.
- for ( var name in data ) {
- if ( ! data.hasOwnProperty( name ) ) {
- continue;
- }
- var value = data[ name ];
- buffer.push(
- encodeURIComponent( name ) +
- "=" +
- encodeURIComponent( ( value == null ) ? "" : value )
- );
- }
- // Serialize the buffer and clean it up for transportation.
- var source = buffer
- .join( "&" )
- .replace( /%20/g, "+" )
- ;
- return( source );
- }
- }
- }
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement