Advertisement
Guest User

Untitled

a guest
Feb 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.94 KB | None | 0 0
  1. $(document).ready(function(){
  2. $("#loginForm").unbind('submit').bind('submit', function() {
  3.     console.log('Form submitted'); // add this line
  4.     var form = $(this);
  5.     var url = form.attr('action');
  6.     var type = form.attr('method');
  7.  
  8.     $.ajax({
  9.         url  : url,
  10.         type : type,
  11.         data : form.serialize(),
  12.         dataType: 'json',
  13.         success:function(response) {
  14.             console.log('Result:'); // add these lines
  15.             console.log(response);
  16.             if(response.success === true) {
  17.                 // commenting out this line... we want to see what is going on
  18.                 //window.location = response.messages;
  19.             }
  20.             else {
  21.                 if(response.messages instanceof Object) {
  22.                     $("#message").html('');    
  23.  
  24.                     $.each(response.messages, function(index, value) {
  25.                         var key = $("#" + index);
  26.  
  27.                         key.closest('.form-group')
  28.                         .removeClass('has-error')
  29.                         .removeClass('has-success')
  30.                         .addClass(value.length > 0 ? 'has-error' : 'has-success')
  31.                         .find('.text-danger').remove();                        
  32.  
  33.                         key.after(value);
  34.  
  35.                     });
  36.                 }
  37.                 else {                      
  38.                     $(".text-danger").remove();
  39.                     $(".form-group").removeClass('has-error').removeClass('has-success');
  40.  
  41.                     $("#message").html('<div class="alert alert-warning alert-dismissible" role="alert">'+
  42.                       '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+
  43.                       response.messages +
  44.                     '</div>');
  45.                 } // /else
  46.             } // /else
  47.         } // /if
  48.     });
  49.  
  50.     return false;
  51. });
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement