You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

104 lines
3.2 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define(['jquery', 'mage/url'], function ($, urlBuilder) {
  6. 'use strict';
  7. return {
  8. /**
  9. * Perform asynchronous GET request to server.
  10. * @param {String} url
  11. * @param {Boolean} global
  12. * @param {String} contentType
  13. * @param {Object} headers
  14. * @returns {Deferred}
  15. */
  16. get: function (url, global, contentType, headers) {
  17. headers = headers || {};
  18. global = global === undefined ? true : global;
  19. contentType = contentType || 'application/json';
  20. return $.ajax({
  21. url: urlBuilder.build(url),
  22. type: 'GET',
  23. global: global,
  24. contentType: contentType,
  25. headers: headers
  26. });
  27. },
  28. /**
  29. * Perform asynchronous POST request to server.
  30. * @param {String} url
  31. * @param {String} data
  32. * @param {Boolean} global
  33. * @param {String} contentType
  34. * @param {Object} headers
  35. * @returns {Deferred}
  36. */
  37. post: function (url, data, global, contentType, headers) {
  38. headers = headers || {};
  39. global = global === undefined ? true : global;
  40. contentType = contentType || 'application/json';
  41. return $.ajax({
  42. url: urlBuilder.build(url),
  43. type: 'POST',
  44. data: data,
  45. global: global,
  46. contentType: contentType,
  47. headers: headers
  48. });
  49. },
  50. /**
  51. * Perform asynchronous PUT request to server.
  52. * @param {String} url
  53. * @param {String} data
  54. * @param {Boolean} global
  55. * @param {String} contentType
  56. * @param {Object} headers
  57. * @returns {Deferred}
  58. */
  59. put: function (url, data, global, contentType, headers) {
  60. var ajaxSettings = {};
  61. headers = headers || {};
  62. global = global === undefined ? true : global;
  63. contentType = contentType || 'application/json';
  64. ajaxSettings.url = urlBuilder.build(url);
  65. ajaxSettings.type = 'PUT';
  66. ajaxSettings.data = data;
  67. ajaxSettings.global = global;
  68. ajaxSettings.contentType = contentType;
  69. ajaxSettings.headers = headers;
  70. return $.ajax(ajaxSettings);
  71. },
  72. /**
  73. * Perform asynchronous DELETE request to server.
  74. * @param {String} url
  75. * @param {Boolean} global
  76. * @param {String} contentType
  77. * @param {Object} headers
  78. * @returns {Deferred}
  79. */
  80. delete: function (url, global, contentType, headers) {
  81. headers = headers || {};
  82. global = global === undefined ? true : global;
  83. contentType = contentType || 'application/json';
  84. return $.ajax({
  85. url: urlBuilder.build(url),
  86. type: 'DELETE',
  87. global: global,
  88. contentType: contentType,
  89. headers: headers
  90. });
  91. }
  92. };
  93. });