Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Send forms with ajax

$(document).ready(function() {
  function SendFormWithAjax(id) {

    $.ajax({
      type: $(id).attr('method'),
      url: $(id).attr('action'),
      data: $(id).serialize(),

      success: function(data) {
        switch (data) {
          case 'success':
            $(id).trigger("reset"); //Reset form
            swal("Success",
                 "Nice",
                 "success");
            break;

          case 'warning':
            swal("Opps",
                 "Warning",
                 "warning");
            break;

          case 'error':
            swal("Error",
                 "Error",
                 "error");
            break;
        }
      }
    });
  }

  $('#form_one_id').on('submit', function(ev) {
    SendFormWithAjax(id);
    ev.preventDefault();
  });

  $('#form_two_id').on('submit', function(ev) {
    SendFormWithAjax(id);
    ev.preventDefault();
  });
});
Source by wlearnsmart.com #
 
PREVIOUS NEXT
Tagged: #Send #forms #ajax
ADD COMMENT
Topic
Name
6+9 =