function api_general(method, data, callback, checked, additional_data) { $.ajax({ type: 'POST', url: '/api/' + method, data: data, success: function (data) { if (checked && data.error !== undefined) popup('danger', 'Error: ' + data.error); else callback(data, additional_data); }, processData: !(data instanceof FormData), contentType: data instanceof FormData? false: 'application/x-www-form-urlencoded', dataType: 'json' }); } function api(method, data, callback) { var additional_data = Array.prototype.slice.call(arguments, 3); api_general(method, data, callback, true, additional_data); } function api_unchecked(method, data, callback) { var additional_data = Array.prototype.slice.call(arguments, 3); api_general(method, data, callback, false, additional_data); }