angular.module('servicios', []) .factory('Utilidades', ['$http', '$rootScope', '$location', function($http,$rootScope, $location){ var baseUrl = $location.protocol() + '://' + $location.host() + ($location.port() == 80 ? '' : ':' + $location.port()) + '/'; return { ejecutarGet: function(uri, onSuccess, onError){ $rootScope.cargando++; $http({ method: 'GET', url: myUrl + uri, headers:{'Cache-Control': 'no-cache'} }).then(function successCallback(response) { console.log(response); if (response.data && response.data.estado){ if (response.data.estado == 1){ if (onSuccess) onSuccess(response.data.contenido); } } $rootScope.cargando--; }, function errorCallback(response) { if (onError) onError(response); else $('#errores').html(response); $rootScope.cargando--; }); }, ejecutarGetSinCarga: function(uri, onSuccess, onError){ $http({ method: 'GET', url: myUrl + uri, headers:{'Cache-Control': 'no-cache'} }).then(function successCallback(response) { if (response.data && response.data.estado){ if (response.data.estado == 1){ if (onSuccess) onSuccess(response.data.contenido); } } }, function errorCallback(response) { if (onError) onError(response); else $('#errores').html(response); }); }, ejecutarPut: function(uri, data, onSuccess, onError){ $rootScope.cargando++; $http({ method: 'PUT', url: myUrl + uri, data: data, headers:{'Cache-Control': 'no-cache'} }).then(function successCallback(response) { console.log(response); if (onSuccess) onSuccess(response); $rootScope.cargando--; }, function errorCallback(response) { if (onError) onError(response); else $('#errores').html(response); $rootScope.cargando--; }); }, getUrl: function(){ return myUrl; } }; }]);