- moving ajax script outside plugin class, as a js file
- wip trying to use the wordpress image editor
This commit is contained in:
19
plugins/fipfcard_plugin/js/image_editor.js
Normal file
19
plugins/fipfcard_plugin/js/image_editor.js
Normal 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);
|
||||
});
|
||||
});
|
||||
@@ -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: ");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user