using wp_localize instead of wp_add_line for ajax

This commit is contained in:
asus
2024-02-11 20:12:57 +01:00
parent 0a4185908b
commit 75bd922fd9
2 changed files with 23 additions and 21 deletions

View File

@@ -1,17 +1,15 @@
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function that create an ajax post action
it can be "overloaded" with a callback_response and _error
*/
function ajax_post(ajax_data, action, callback_response, callback_error) {
console.log("in ajac_post, ajax_data :");
console.log(ajax_data);
const data = new FormData();
data.append('action', action);
data.append('_ajax_nonce', nonce);
data.append('_ajax_nonce', wp_ajax._nonce);
data.append('data', ajax_data);
console.log("data: ");
console.log(data);
fetch(ajax_url, {
fetch(wp_ajax._url, {
method: 'POST',
credentials: 'same-origin',
body: data