I have created a simple backend-frontend (HTML-JavaScript-CSS-PHP) contact form to transfer contact form inquiries to my local email client (i.e. local in the sense that it sits on the same web hosting provider environment of my website shared hosting environment).
The PHP pattern is:
<?php
$contact_form_url="example.com/contact";
$to = "example@example.com";
$subject = "New email message";
$message = "Message";
mail($to, $subject, $message);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
header("Location: $contact_form_url");
exit;
}
?>
As can be understood from the code; after the form is submitted the user is supposed to stay on the same webpage (some kind of a “refresh webpage” action on the contact form’s URL).
What I desire to have is the user getting some AJAX/AJAJ/XHR/JHR alert()
or popup/modal message like “Thanks! I should most likely get back to you as soon as possible!” between the form submission and the refreshing of the page.
How would you achieve that in vanilla JavaScript?