Last active
December 24, 2015 20:59
-
-
Save rajnathani/6862340 to your computer and use it in GitHub Desktop.
layer about jquery ajax calls
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
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