wip make ajax automatically added
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
function ajax_post(data, action, callback_response, callback_error) {
|
||||
/*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*/
|
||||
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', data);
|
||||
data.append('data', mydata);
|
||||
|
||||
fetch(php_data.ajax_url, {
|
||||
method: 'POST',
|
||||
|
||||
@@ -3,26 +3,6 @@ const sendButton = document.getElementById('mybutton');
|
||||
|
||||
sendButton.addEventListener('click', () => {
|
||||
const inputValue = inputElement.value;
|
||||
const myurl = php_data.ajax_url;
|
||||
console.log(myurl);
|
||||
|
||||
const data = new FormData();
|
||||
data.append('action', 'get_data',);
|
||||
data.append('_ajax_nonce', php_data.nonce);
|
||||
data.append('data', inputValue);
|
||||
|
||||
fetch(myurl, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
body: data
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
console.log("data: ");
|
||||
console.log(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error: ");
|
||||
console.log(error);
|
||||
});
|
||||
ajax_post(inputValue, 'get_data');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user