HTML CODE
Код: Выделить всё
Send Data
Код Javascript
Код: Выделить всё
document.getElementById('myButton').addEventListener('click', function() {
const inputValue = document.getElementById('myInput').value;
const data = { inputData: inputValue }; // Create an object to send
fetch('p.php', { // Replace with your PHP script path
method: 'POST',
headers: {
'Content-Type': 'application/json', // Specify content type
},
body: JSON.stringify(data), // Convert data to JSON string
})
.then(response => response.text()) // Or .json() if PHP returns JSON
.then(responseText => {
document.getElementById('responseArea').innerHTML = responseText;
})
.catch(error => {
console.error('Error:', error);
});
});
Кто-нибудь может это сделать?
Подробнее здесь: https://stackoverflow.com/questions/797 ... ick-button