Googling how to achieve this is proving difficult as everyone seems determined to get you to use jQuery for every simple task these days. I've made a rich experience on my site and gone to great lengths to avoid unnecessarily using jQuery, and now that I've come to the contact form, I'm slightly stumped.
On a previous website I used jQuery to submit a form without refreshing the page and then get the result and display it in a div under the form. Now I want to achieve the same effect without jQuery. This is the code I used before:
$('#contactform').submit(function(event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "contact.php",
data: $(this).serialize(),
success: function(data){
$('#result').html(data);
}
});
});
Can someone please help me to achieve this in pure JS? This is the last thing on my site that requires JavaScript so I really don't want to have to invoke jQuery now for something so simple as all my effort to code lovely scroll-to-top buttons, retina image replacement, sliders, and drop-down menus without it will all have been in vain...