Advertisement
Guest User

Sending Script

a guest
May 11th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module('testSendData', [])
  2.  
  3. .controller('sendDataCtrl', function($scope, $http, $window, $exceptionHandler){
  4.     $scope.username = "";
  5.     $scope.pass = "";
  6.  
  7.     $scope.sendData = function(){
  8.         if($scope.username == "") {
  9.             $window.alert("Username Field Is Empty");
  10.             return;
  11.         }
  12.         else if($scope.pass == "") {
  13.             $window.alert("Password Field Is Empty");
  14.             return;
  15.         }
  16.  
  17.         var data = {details: JSON.stringify({
  18.                 username: $scope.username,
  19.                 password : $scope.pass
  20.             })
  21.         };
  22.         console.log("Data That Going To Be Sent as json: ");
  23.         console.log(data);
  24.  
  25.         $http.post("server", data).
  26.         success(function(data) {
  27.             console.log("Sended Username: " + $scope.username + " pass: " + $scope.pass);      
  28.         }).error(function(data) {
  29.             console.error("error in posting");
  30.         });
  31.        
  32.     }
  33.    
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement