@@ -53,16 +53,16 @@ With that being said, let's jump on in to some examples! First, we'll see how ea
53
53
// Using validation to check for the presence of an input
54
54
$("#form").submit(function( e ) {
55
55
56
- if ( $(".required").val().length === 0 ) { // if .required's value's length is zero
56
+ if ( $(".required").val().length === 0 ) { // if .required's value's length is zero
57
57
58
- // usually show some kind of error message here
59
- return false; // this prevents the form from submitting
58
+ // usually show some kind of error message here
59
+ return false; // this prevents the form from submitting
60
60
61
- } else {
61
+ } else {
62
62
63
- // run $.ajax here
63
+ // run $.ajax here
64
64
65
- }
65
+ }
66
66
67
67
});
68
68
```
@@ -73,19 +73,19 @@ Let's see how easy it is to check for invalid characters in a username:
73
73
// Validate a phone number field
74
74
$("#form").submit(function( e ) {
75
75
76
- var inputtedPhoneNumber = $("#phone").val();
76
+ var inputtedPhoneNumber = $("#phone").val();
77
77
var phoneNumberRegex = ^\d*$/; // match only numbers
78
78
79
- if ( !phoneNumberRegex.test( inputtedPhoneNumber ) ) { // if the phone number doesn't match the regex
79
+ if ( !phoneNumberRegex.test( inputtedPhoneNumber ) ) { // if the phone number doesn't match the regex
80
80
81
- // usually show some kind of error message ere
82
- return false; // prevent the form from submitting
81
+ // usually show some kind of error message ere
82
+ return false; // prevent the form from submitting
83
83
84
- } else {
84
+ } else {
85
85
86
- // run $.ajax here
86
+ // run $.ajax here
87
87
88
- }
88
+ }
89
89
90
90
});
91
91
```
@@ -99,13 +99,13 @@ For example, say we would like to modify all crossDomain requests through a prox
99
99
// Using a proxy with a prefilter
100
100
$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
101
101
102
- if ( options.crossDomain ) {
102
+ if ( options.crossDomain ) {
103
103
104
- options.url = "http://mydomain.net/proxy/" + encodeURIComponent(options.url );
104
+ options.url = "http://mydomain.net/proxy/" + encodeURIComponent(options.url );
105
105
106
- options.crossDomain = false;
106
+ options.crossDomain = false;
107
107
108
- }
108
+ }
109
109
110
110
});
111
111
```
@@ -116,7 +116,7 @@ You can pass in an optional argument before the callback function that specifies
116
116
// Using the optional dataTypes argument">
117
117
$.ajaxPrefilter( "json script", function( options, originalOptions, jqXHR ) {
118
118
119
- // do all of the prefiltering here, but only for requests that indicate a dataType of "JSON" or "script"
119
+ // do all of the prefiltering here, but only for requests that indicate a dataType of "JSON" or "script"
120
120
121
121
});
122
122
```
0 commit comments