Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.2 kB
3
Indexable
Never
    <script>
    const form = document.querySelector(".contact-form");
    if (form) {
        form.addEventListener("submit", function (event) {
            event.preventDefault();
            console.log("submit");
            var request = new XMLHttpRequest();
            var url = "/mail.php";
            request.open("POST", url, true);
        
            request.onreadystatechange = function () {
                if (request.readyState === 4 && request.status === 200) {
                    console.log(request.response);
                    var jsonData = JSON.parse(request.response);
                    console.log(jsonData);
                }
            };
        
            var name = document.getElementById("name").value;
            var courriel = document.getElementById("courriel").value;
            var phone = document.getElementById("phone").value;
            var message = document.getElementById("message").value;

            request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            request.send("name=" + name + "&courriel=" + courriel + "&phone=" + phone + "&message=" + message);
        });
    }
    </script>
Leave a Comment