ajax is working

This commit is contained in:
asus
2024-02-10 12:05:50 +01:00
parent 4e18b21406
commit 0b2e6352e1
2 changed files with 30 additions and 9 deletions

View File

@@ -6,13 +6,23 @@ sendButton.addEventListener('click', () => {
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: JSON.stringify({
action: 'get_data',
_ajax_nonce: php_data.nonce,
data: inputValue,
})
body: data
})
.then((response) => response.json())
.then((data) => {
console.log("data: ");
console.log(data);
})
.catch((error) => {
console.log("error: ");
console.log(error);
});
});