const form = document.querySelector(".wrapper form"), fullURL = form.querySelector("input"), shortenBtn = form.querySelector("form button"), urlsArea = document.querySelector(".urls-area"); form.onsubmit = (e) => { e.preventDefault(); }; shortenBtn.onclick = () => { let xhr = new XMLHttpRequest(); xhr.open("POST", "php/url-controll.php", true); xhr.onload = () => { if (xhr.readyState == 4 && xhr.status == 200) { let data = xhr.response; if (data.length <= 5) { // Example of setting the shortened URL directly to the list let domain = "localhost/url/"; let shortenURL = domain + data; // Create a new row for the URL and append it to the list let newRow = `
  • ${shortenURL}
  • ${fullURL.value}
  • 0
  • Delete
  • `; urlsArea.insertAdjacentHTML('afterbegin', newRow); } else { alert(data); } } }; let formData = new FormData(form); xhr.send(formData); };