Advertisement
Ranga14

Gotpix.com JQuery/AJAX Commenting

Aug 14th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2. $('#PP_Post').on('submit', function(e) {
  3.     var $btn = $(this).find('.Submit');
  4.  
  5.     $btn.attr('disabled', true);
  6.     $btn.val('Posting...');
  7.  
  8.     e.preventDefault();
  9.  
  10.     $.ajax({
  11.             type: 'POST',
  12.             data: $('#PP_Post').serialize(),
  13.             url: $(this).attr('action'),
  14.             success: function(msg) {
  15.                 var targetOffset = $('#Profile_Posts').offset().top;
  16.  
  17.                 // Insert post
  18.                 $(msg).insertBefore('#Profile_Posts .most_recent');
  19.  
  20.                 // Scroll to top of posts
  21.                 $("body, html").animate({scrollTop: targetOffset}, 600);
  22.  
  23.                 // Re-enable submit button
  24.                 $btn.removeAttr('disabled');
  25.  
  26.                 // Update button text
  27.                 $btn.val('POST');
  28.  
  29.                 // Clear old post message
  30.                 $('#PP_Post .descriptionField').val('');
  31.             }
  32.     });
  33. });
  34. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement