wp_back/wp-content/plugins/wp-smushit/_src/react/utils/request.js
2024-05-20 15:37:46 +03:00

24 lines
465 B
JavaScript

import $ from 'jquery';
import ajaxUrl from 'ajaxUrl';
export function post(action, nonce, data = {}) {
return new Promise(function (resolve, reject) {
const request = Object.assign({}, {
action: action,
_ajax_nonce: nonce
}, data);
$.post(ajaxUrl, request)
.done((response) => {
if (response.success) {
resolve(
response?.data
);
} else {
reject(response?.data?.message);
}
})
.fail(() => reject());
});
}