1$(function() { 2 3 // Get the form. 4 var form = $('#ajax-contact'); 5 6 // Get the messages div. 7 var formMessages = $('#form-messages'); 8 9 // Set up an event listener for the contact form. 10 $(form).submit(function(e) { 11 // Stop the browser from submitting the form. 12 e.preventDefault(); 13 14 // Serialize the form data. 15 var formData = $(form).serialize(); 16 17 // Submit the form using AJAX. 18 $.ajax({ 19 type: 'POST', 20 url: $(form).attr('action'), 21 data: formData 22 }) 23 .done(function(response) { 24 // Make sure that the formMessages div has the 'success' class. 25 $(formMessages).removeClass('error'); 26 $(formMessages).addClass('success'); 27 28 // Set the message text. 29 $(formMessages).text(response); 30 31 // Clear the form. 32 $('#name').val(''); 33 $('#email').val(''); 34 $('#message').val(''); 35 }) 36 .fail(function(data) { 37 // Make sure that the formMessages div has the 'error' class. 38 $(formMessages).removeClass('success'); 39 $(formMessages).addClass('error'); 40 41 // Set the message text. 42 if (data.responseText !== '') { 43 $(formMessages).text(data.responseText); 44 } else { 45 $(formMessages).text('Oops! An error occured and your message could not be sent.'); 46 } 47 }); 48 49 }); 50 51});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.