Skip to content

Instantly share code, notes, and snippets.

Created September 19, 2016 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d196a7749c2c35181081433fd882faca to your computer and use it in GitHub Desktop.
Save anonymous/d196a7749c2c35181081433fd882faca to your computer and use it in GitHub Desktop.
CRUD com AngularJS e CodeIgniter - myServices
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