This is what's comes to my mind with "generic" - but it's still asynchronous:
function CallMethod(url, parameters, successCallback) {
//show loading... image
$.ajax({
type: 'POST',
url: url,
data: JSON.stringify(parameters),
contentType: 'application/json;',
dataType: 'json',
success: successCallback,
error: function(xhr, textStatus, errorThrown) {
console.log('error');
}
});
}
CallMethod(url, pars, onSuccess);
function onSuccess(param) {
//remove loading... image
//do something with the response
}