api.js 865 B

123456789101112131415161718192021222324252627
  1. function api_general(method, data, callback, checked, additional_data) {
  2. $.ajax({
  3. type: 'POST',
  4. url: '/api/' + method,
  5. data: data,
  6. success: function (data) {
  7. if (checked && data.error !== undefined)
  8. popup('danger', 'Error: ' + data.error);
  9. else callback(data, additional_data);
  10. },
  11. processData: !(data instanceof FormData),
  12. contentType: data instanceof FormData? false: 'application/x-www-form-urlencoded',
  13. dataType: 'json'
  14. });
  15. }
  16. function api(method, data, callback) {
  17. var additional_data = Array.prototype.slice.call(arguments, 3);
  18. api_general(method, data, callback, true, additional_data);
  19. }
  20. function api_unchecked(method, data, callback) {
  21. var additional_data = Array.prototype.slice.call(arguments, 3);
  22. api_general(method, data, callback, false, additional_data);
  23. }