- moving ajax script outside plugin class, as a js file

- wip trying to use the wordpress image editor
This commit is contained in:
asus
2024-02-19 00:46:03 +01:00
parent e9032647f2
commit 04c4ea31d5
9 changed files with 97 additions and 105 deletions

View File

@@ -0,0 +1,19 @@
console.log("---------------inside image_editor.js--------------");
const edit_image_button = document.getElementById('edit_image');
const image_id_field = document.getElementById('image_id');
edit_image_button.addEventListener('click', () => {
const image_id = image_id_field.value;
PLGNTLS_ajax("postid", image_id, 'image_editor')
.then((response) => response.json())
.then((data) => {
console.log("data: ");
console.log(data);
})
.catch((error) => {
console.log("error: ");
console.log(error);
});
});

View File

@@ -5,8 +5,7 @@ sendButton.addEventListener('click', () => {
const inputValue = inputElement.value;
console.log("inputValue:");
console.log(inputValue);
console.log(PLGNTLS_data);
PLGNTLS_data.ajax(inputValue, 'get_data')
PLGNTLS_ajax(inputValue, 'get_data')
.then((response) => response.json())
.then((data) => {
console.log("dataaa: ");

View File

@@ -1,34 +0,0 @@
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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) {
const data = new FormData();
data.append('action', action);
data.append('_ajax_nonce', fipfcard_ajax._nonce);
data.append('data', ajax_data);
fetch(fipfcard_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);
}
});
};