Files
WORDPRESS_PLUGIN_model/plugins/wp_model_plugin/js/ajax.js
2024-02-10 19:19:47 +01:00

33 lines
705 B
JavaScript

/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
function ajax_post(mydata, action, callback_response, callback_error) {
const data = new FormData();
data.append('action', action);
data.append('_ajax_nonce', php_data.nonce);
data.append('data', mydata);
fetch(php_data.ajax_url, {
method: 'POST',
credentials: 'same-origin',
body: data
})
.then((response) => response.json())
.then((data) => {
if (callback_response)
callback_response(data);
else {
console.log("data: ");
console.log(data);
}
})
.catch((error) => {
if (callback_error)
callback_error(error);
else {
console.log("error: ");
console.log(error);
}
});
};