jQuery in Action

282
CHAPTER 9
Prominent, powerful, and practical plugins
We could leverage our knowledge of event handling and the
ajaxSubmit()
command to reroute the submission ourselves. As it turns out, we won't have to;
the Form Plugin anticipates this need with the
ajaxForm()
method.
This method instruments the form so that the submission is blocked when the
form is submitted through one of the normal semantics events (such as clicking a
submit button or pressing the Enter key when the form has focus) and an Ajax
request that emulates the request is initiated.
ajaxForm()
uses
ajaxSubmit()
under the covers, so it's not surprising that their
syntaxes are similar.
Typically, we apply
ajaxForm()
to a form in the ready handler; then, we can forget
about it and let the command apply instrumentation to reroute the form submis-
sion on our behalf.
It's possible, indeed customary, to declare the markup for
HTML
forms as if
they are going to be submitted normally and to let
ajaxForm()
pick up these val-
ues from the declaration of the form. For times when users have disabled Java-
Script, the form degrades gracefully and submits normally without us having to
do anything special whatsoever. How convenient!
If, at some point after a form has been bound with
ajaxForm()
, we need to
remove the instrumentation to let the form submit normally, the
ajaxForm-
Unbind()
command will accomplish that.
For fans of the lab pages, an ajaxForm Laboratory can be found in the file
chapter9/form/lab.ajaxForm.html. Loaded into a browser, this page will appear as
shown in figure 9.5.
Command syntax: ajaxForm
ajaxForm(options)
Instruments the target form so that when submission of the form is triggered, the submis-
sion reroutes through an Ajax request initiated via the ajaxSubmit() command. The
options
parameter passed to this method is passed on to the ajaxSubmit() call.
Parameters
options
(Object|Function) An optional object hash containing properties as described in
table 9.1. If the only desired option is a success callback, it can be passed in
place of the options hash.
Returns
The wrapped set.


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.