×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Joel Quenard
Added: Apr 27, 2022 11:23 PM
Modified: Apr 28, 2022 12:27 AM
Views: 13
Tags: no tags
  1.     $("#form").submit(function (e) {
  2.         e.preventDefault();
  3.         var form = $(this);
  4.         var url = form.attr('action');
  5.         $.ajax({
  6.             type: "POST",
  7.             url: url,
  8.             data: new FormData(this),
  9.             processData: false,
  10.             contentType: false,
  11.             error: function (response) {
  12.                 Swal.fire({
  13.                     icon: 'error',
  14.                     title: 'Error',
  15.                     text: response.responseText
  16.                 });
  17.             },
  18.             success: function () {
  19.                 Swal.fire({
  20.                     icon: 'success',
  21.                     title: 'Operacion correcta'
  22.                 }).then(function() {
  23.                     window.location = "redirectURL";
  24.                 });
  25.             }
  26.         });
  27.     });