jordanisip (owner)

Revisions

gist: 27607 Download_button fork
public
Public Clone URL: git://gist.github.com/27607.git
Embed All Files: show embed
JavaScript #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(function($){
$.fixieAjaxForm = function(onSuccess) {
  // $('form').fixieAjaxForm()
  // $(this) == $('form') inside this function
  $(this).ajaxForm(function(str) {
    var data = $.parseJSON(str);
    $(this).find('label.error').removeClass('error');
    if (data.errors.length === 0) {
      $(this).resetForm();
      onSuccess(data);
    } else {
      $.each(data.errors, function(){
        $('label[for='+ this[0]+']').addClass('error');
      });
    }
  })
}
})(jQuery);