Browse Source

#37: Update the README, adding an example of how to use Ajax to submit the form

nghuuphuoc 12 years ago
parent
commit
e13e39b146
1 changed files with 17 additions and 1 deletions
  1. 17 1
      README.md

+ 17 - 1
README.md

@@ -82,7 +82,7 @@ $(document).ready(function() {
 
 
 ```feedbackIcons```: Show valid/invalid/validating icons based on the field validity.
 ```feedbackIcons```: Show valid/invalid/validating icons based on the field validity.
 
 
-This feature requires Bootstrap v3.1.0 or later (http://getbootstrap.com/css/#forms-control-validation).
+This feature requires [Bootstrap v3.1.0 or later](http://getbootstrap.com/css/#forms-control-validation).
 Since Bootstrap doesn't provide any methods to know its version, this option cannot be on/off automatically.
 Since Bootstrap doesn't provide any methods to know its version, this option cannot be on/off automatically.
 In other word, to use this feature you have to upgrade your Bootstrap to v3.1.0 or later.
 In other word, to use this feature you have to upgrade your Bootstrap to v3.1.0 or later.
 
 
@@ -110,12 +110,28 @@ feedbackIcons: {
 
 
 ```submitHandler```: Custom submit handler.
 ```submitHandler```: Custom submit handler.
 
 
+```javascript
+submitHandler: function(validator, form, submitButton) {
+},
+```
+
 The handler has three arguments:
 The handler has three arguments:
 
 
 - ```validator``` is the instance of BootstrapValidator
 - ```validator``` is the instance of BootstrapValidator
 - ```form``` is jQuery object representing the current form
 - ```form``` is jQuery object representing the current form
 - ```submitButton``` is jQuery object representing the submit button which is clicked
 - ```submitButton``` is jQuery object representing the submit button which is clicked
 
 
+This option is useful when you want to use Ajax to submit the form data:
+
+```javascript
+submitHandler: function(validator, form, submitButton) {
+    // Use Ajax to submit form data
+    $.post(form.attr('action'), form.serialize(), function(result) {
+        // ... process the result ...
+    }, 'json');
+}
+```
+
 By default, ```submitHandler``` is ```null```
 By default, ```submitHandler``` is ```null```
 
 
 ```live```: Live validating. Can be one of 3 values:
 ```live```: Live validating. Can be one of 3 values: