The method
returns null if readyState value is not 3 or 4.
1.5 Sending an Ajax Request 7
1.5 Sending an Ajax Request
In Ajax, many requests that use the XMLHttpRequest are initiated from
a HTML Event such as a button click (onclick) or a key press
(onkeypress) that invokes a JavaScript function. Ajax has various
applications including form validation. Sometimes a unique form field is
required to be validated before the rest of the form may be filled. For
example a registration form that requires a unique UserID. Without
validation of the UserID field with Ajax the complete form would have to
be filled and submitted. If the UserID is not valid, the form would have to
be re-submitted. For example, a form field for a Catalog ID that must be
validated on the server might be specified as follows.
The preceding HTML uses the validationMessage div to display a
validation message for the input field Catalog Id. The onkeyup event
invokes a JavaScript sendRequest() function. The sendRequest()
function creates an XMLHttpRequest object. The process of creating an
XMLHttpRequest object differs depending on the browser
implementation.
Pages:
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35