Skip to content

Instantly share code, notes, and snippets.

@rajnathani
Last active December 24, 2015 20:59
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 rajnathani/6862340 to your computer and use it in GitHub Desktop.
Save rajnathani/6862340 to your computer and use it in GitHub Desktop.
layer about jquery ajax calls
function go_ajax(url, method, data, success_func, extra_dict) {
if ($.type(data) === "function") {
var success_func_holder = success_func;
success_func = data;
extra_dict = success_func_holder;
data = undefined;
}
$.ajax({
url: url,
type: method,
data: data ? JSON.stringify(data) : null,
contentType: "application/json;charset=UTF-8",
success: success_func,
complete: extra_dict && extra_dict.complete ? extra_dict.complete : null,
error: extra_dict && extra_dict.error ? extra_dict.error : function ($ajax) {
if ($ajax.statusCode === 500){
pop('Damn the server, something went wrong with it.', 'error');
} else if ($ajax.statusCode === 400){
pop('Something went wrong!')
} else {
pop('An error occurred', 'error')
}
},
context: extra_dict && extra_dict.context ? extra_dict.context : null
});
}
function bring_json(url, data, func) {
$.getJSON(url, data, func);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment