Когда я нажимаю кнопку, получается исходный код HTML.

Я хочу просмотреть весь HTML как дизайн.

МОИ КОДЫ
Код: Выделить всё
Extract
При получении результата из fetch.php данные будут получены в виде исходного кода HTML. Здесь я хочу просмотреть весь HTML как стиль.
Код: Выделить всё
document.addEventListener('DOMContentLoaded', () => {
const myInput = document.getElementById('myInput');
const myButton = document.getElementById('myButton');
const loadingSpinner = document.getElementById('loadingSpinner');
const resultDiv = document.getElementById('result');
myButton.addEventListener('click', () => {
const inputValue = myInput.value;
// Show loading spinner
loadingSpinner.style.display = 'block';
myButton.disabled = true; // Disable button during loading
// Create a new XMLHttpRequest object
const xhr = new XMLHttpRequest();
// Configure the request
xhr.open('POST', 'fetch.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
// Define what happens on successful data reception
xhr.onload = () => {
if (xhr.status === 200) {
resultDiv.textContent = xhr.responseText;
} else {
resultDiv.textContent = 'Error: ' + xhr.status;
}
// Hide loading spinner and re-enable button
loadingSpinner.style.display = 'none';
myButton.disabled = false;
};
// Define what happens in case of an error
xhr.onerror = () => {
resultDiv.textContent = 'Network error.';
loadingSpinner.style.display = 'none';
myButton.disabled = false;
};
// Send the request with the input value
xhr.send('data=' + encodeURIComponent(inputValue));
});
});
Кто-нибудь менял приведенный выше код? Пожалуйста, отредактируйте его и пришлите мне.
Подробнее здесь: https://stackoverflow.com/questions/797 ... ource-code