Advertisement
Guest User

Financial Ajax function

a guest
Apr 8th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.13 KB | None | 0 0
  1. $(document).ready(function() {
  2.     let financing_form = $('#financing_form');
  3.     $('#financing_form .alert').hide();
  4.  
  5.     financing_form.submit(function(e) {
  6.         e.preventDefault();
  7.         $('#financing_form .alert').removeClass('alert-danger alert-success');
  8.        
  9.     $.ajax({
  10.             url: '/financings',
  11.             type: 'POST',
  12.             dataType: 'json',
  13.             data: financing_form.serialize()
  14.         })
  15.         .done(function(data) {
  16.             $('#financing_form .alert').show()
  17.             .addClass('alert-success');
  18.             $('.alert ul').html('<li>Success add data</li>');
  19.  
  20.             $('.modal').animate({scrollTop: '11px'}, 500);
  21.             console.log(data);
  22.         })
  23.         .fail(function(data) {
  24.             $('#financing_form .alert').show();
  25.             $('#financing_form .alert').addClass('alert-danger');
  26.  
  27.             let errors = data.responseJSON.errors;
  28.             let error_msg = "";
  29.             console.log("error");
  30.             console.log(errors);
  31.            
  32.             for(let error in errors){
  33.                 console.log(errors[error]);
  34.                 error_msg += '<li>' + errors[error] + '</li>';
  35.             }
  36.  
  37.             $('.alert.alert-danger ul').html(error_msg);           
  38.             $('.modal').animate({scrollTop: '11px'}, 500);
  39.         })
  40.         .always(function() {
  41.             console.log("complete");
  42.         });
  43.     });
  44. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement