storage.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * @returns {Deferred}
  14. */
  15. get: function (url, global, contentType) {
  16. global = global === undefined ? true : global;
  17. contentType = contentType || 'application/json';
  18. return $.ajax({
  19. url: urlBuilder.build(url),
  20. type: 'GET',
  21. global: global,
  22. contentType: contentType
  23. });
  24. },
  25. /**
  26. * Perform asynchronous POST request to server.
  27. * @param {String} url
  28. * @param {String} data
  29. * @param {Boolean} global
  30. * @param {String} contentType
  31. * @returns {Deferred}
  32. */
  33. post: function (url, data, global, contentType) {
  34. global = global === undefined ? true : global;
  35. contentType = contentType || 'application/json';
  36. return $.ajax({
  37. url: urlBuilder.build(url),
  38. type: 'POST',
  39. data: data,
  40. global: global,
  41. contentType: contentType
  42. });
  43. },
  44. /**
  45. * Perform asynchronous PUT request to server.
  46. * @param {String} url
  47. * @param {String} data
  48. * @param {Boolean} global
  49. * @param {String} contentType
  50. * @returns {Deferred}
  51. */
  52. put: function (url, data, global, contentType) {
  53. global = global === undefined ? true : global;
  54. contentType = contentType || 'application/json';
  55. return $.ajax({
  56. url: urlBuilder.build(url),
  57. type: 'PUT',
  58. data: data,
  59. global: global,
  60. contentType: contentType
  61. });
  62. },
  63. /**
  64. * Perform asynchronous DELETE request to server.
  65. * @param {String} url
  66. * @param {Boolean} global
  67. * @param {String} contentType
  68. * @returns {Deferred}
  69. */
  70. delete: function (url, global, contentType) {
  71. global = global === undefined ? true : global;
  72. contentType = contentType || 'application/json';
  73. return $.ajax({
  74. url: urlBuilder.build(url),
  75. type: 'DELETE',
  76. global: global,
  77. contentType: contentType
  78. });
  79. }
  80. };
  81. });