Created
September 19, 2016 16:09
-
-
Save anonymous/d196a7749c2c35181081433fd882faca to your computer and use it in GitHub Desktop.
CRUD com AngularJS e CodeIgniter - myServices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory('dataFactory', function($http) { | |
var myService = { | |
httpRequest: function(url,method,params,dataPost,upload) { | |
var passParameters = {}; | |
passParameters.url = url; | |
if (typeof method == 'undefined'){ | |
passParameters.method = 'GET'; | |
}else{ | |
passParameters.method = method; | |
} | |
if (typeof params != 'undefined'){ | |
passParameters.params = params; | |
passParameters.params = params; | |
} | |
if (typeof dataPost != 'undefined'){ | |
passParameters.data = dataPost; | |
} | |
if (typeof upload != 'undefined'){ | |
passParameters.upload = upload; | |
} | |
var promise = $http(passParameters).then(function (response) { | |
if(typeof response.data == 'string' && response.data != 1){ | |
if(response.data.substr('loginMark')){ | |
location.reload(); | |
return; | |
} | |
$.gritter.add({ | |
title: 'Aplicação', | |
text: response.data | |
}); | |
return false; | |
} | |
if(response.data.jsMessage){ | |
$.gritter.add({ | |
title: response.data.jsTitle, | |
text: response.data.jsMessage | |
}); | |
} | |
return response.data; | |
},function(){ | |
$.gritter.add({ | |
title: 'Aplicação', | |
text: 'Ocorreu um erro ao processar a solicitação' | |
}); | |
}); | |
return promise; | |
} | |
}; | |
return myService; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment