document.addEventListener("DOMContentLoaded", function() { document.getElementById("whoisForm").addEventListener("submit", function(e) { e.preventDefault(); var xhr = new XMLHttpRequest(); var formData = new FormData(this); xhr.open("POST", "checkWhois.php", true); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { var resultDiv = document.getElementById("result"); if (xhr.status === 200) { var data = JSON.parse(xhr.responseText); if (data.error) { resultDiv.innerHTML = '
' + data.error + '
'; } else { resultDiv.innerHTML = '
' + data.result + '
'; } } else { resultDiv.innerHTML = '
An error occurred. Please try again.
'; } } }; xhr.onloadstart = function() { document.getElementById("result").innerHTML = '
Loading...
'; }; xhr.send(formData); }); });