Guest User

Untitled

a guest
Apr 7th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module('angularSoap', [])
  2.  
  3. .factory("$soap",['$q',function($q){
  4.     return {
  5.         post: function(url, action, params){
  6.             var deferred = $q.defer();
  7.            
  8.             //Create SOAPClientParameters
  9.             var soapParams = new SOAPClientParameters();
  10.             for(var param in params){
  11.                 soapParams.add(param, params[param]);
  12.             }
  13.            
  14.             //Create Callback
  15.             var soapCallback = function(e){
  16.                 if(e.constructor.toString().indexOf("function Error()") != -1){
  17.                     deferred.reject("An error has occurred.");
  18.                 } else {
  19.                     deferred.resolve(e);
  20.                 }
  21.             }
  22.            
  23.             SOAPClient.invoke(url, action, soapParams, true, soapCallback);
  24.  
  25.             return deferred.promise;
  26.         }
  27.     }
  28. }]);
  29.  
  30.  
  31.  
  32. angular.module('myApp', ['angularSoap'])
  33.  
  34. .factory("testService", ['$soap',function($soap){
  35.     var base_url = "http://localhost/ws_ldap/InputServer.php";
  36.    
  37.     return {
  38.         getExternalI: function(){
  39.             return $soap.post(base_url, "getExternalI");           
  40.         }
  41.  
  42.     }
  43. }])
  44.  
  45. .controller('MainCtrl', function($scope, testService) {
  46.  
  47.   testService.getExternalI().then(function(response){
  48.  
  49.     $scope.myData = response;
  50.     console.log(response);
  51.   });
  52.  
  53. })
Add Comment
Please, Sign In to add comment