mail-script.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. // ------- Mail Send ajax
  2. $(document).ready(function() {
  3. var form = $('#myForm'); // contact form
  4. var submit = $('.submit-btn'); // submit button
  5. var alert = $('.alert-msg'); // alert div for show alert message
  6. // form submit event
  7. form.on('submit', function(e) {
  8. e.preventDefault(); // prevent default form submit
  9. $.ajax({
  10. url: 'mail.php', // form action url
  11. type: 'POST', // form submit method get/post
  12. dataType: 'html', // request type html/json/xml
  13. data: form.serialize(), // serialize form data
  14. beforeSend: function() {
  15. alert.fadeOut();
  16. submit.html('Sending....'); // change submit button text
  17. },
  18. success: function(data) {
  19. alert.html(data).fadeIn(); // fade in response data
  20. form.trigger('reset'); // reset form
  21. submit.attr("style", "display: none !important");; // reset submit button text
  22. },
  23. error: function(e) {
  24. console.log(e)
  25. }
  26. });
  27. });
  28. });