Skip to content

Instantly share code, notes, and snippets.

@thiagomarinho
Last active October 13, 2015 00:57
Show Gist options
  • Select an option

  • Save thiagomarinho/4113902 to your computer and use it in GitHub Desktop.

Select an option

Save thiagomarinho/4113902 to your computer and use it in GitHub Desktop.
Atalho pra requisições ajax com callback tudo bunitin
function ajaxRequest(config, complete, success, error) {
jQuery.ajax(config)
.complete(function(jqXHR, textStatus) {
if (jQuery.isFunction(complete)) {
complete();
}
switch (textStatus) {
case "error" :
case "timeout" :
case "abort" :
case "parseerror" :
if (jQuery.isFunction(error)) {
error(jqXHR.responseText);
}
break;
case "success" :
case "notmodified" :
if (jQuery.isFunction(success)) {
success(jqXHR.responseText);
}
break;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment