const inputElement = document.getElementById('mytext'); 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); }); });