I would like to change the name and write "exito" (success in spanish) instead of .then() and "error" instead of catch().
Here is my code.
How can I manage with this?
var url = 'http://devmsadasds';
var object = null;
var dataServicio = new dataService(url, object, $scope, $routeParams, $controller, $timeout, $http, $q);
dataServicio.ajaxPeticion(url, object, $scope, $routeParams, $controller, $timeout, $http, $q)
.then( function(response){
$scope.datosVista = response;
})
.catch( function(err){
alert(err);
});
}
function dataService(url, object, $scope, $routeParams, $controller, $timeout, $http, $q) {
return {
ajaxPeticion : ajaxPeticion
}
function ajaxPeticion(url, object, $scope, $routeParams, $controller, $timeout, $http, $q) {
if(object === null || object === undefined) {
var metodo = 'GET';
}
else {
var metodo = 'POST';
}
var deferred = $q.defer();
var promise = deferred.promise;
$http({
method: metodo,
url: url,
data: object,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.then(function(response) {
if(response.data.jsonMC.resultado === false || response.status != 200 || response.data.jsonMC.respuesta === null) {
deferred.reject(response.data.jsonMC.error);
}
else {
deferred.resolve(response.data.jsonMC.respuesta);
}
}, function errorCallback(response) {
deferred.rejected(response.data.jsonMC.error);
});
return promise;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…