jQuery in Action

276
CHAPTER 9
Prominent, powerful, and practical plugins
Now let's see how the Form Plugin helps us to submit forms via Ajax requests.
9.1.3 Submitting forms through Ajax
Back in chapter 8, we saw how easy jQuery makes initiating Ajax requests, but the
Form Plugin makes things even easier. We could use the serialization commands
introduced in section 9.1.1, but wait! There's more! The Form Plugin makes it
even easier to hijack form requests.
The Form Plugin introduces two new commands for submitting forms via
Ajax: one that initiates an Ajax request under script control, passing data in a tar-
get form as the request's parameters, and another that instruments any form to
reroute its submission as an Ajax request.
Both approaches use the jQuery Ajax core functions to perform the Ajax
request, so all the global jQuery hooks continue to be applied even when using
these methods in place of the core jQuery Ajax
API
.
Let's start by examining the first approach.
Grabbing form data for an Ajax request
When we developed the e-commerce examples of chapter 8, we encountered a
number of situations in which we needed to grab values from form controls to
send them to the server via an Ajax request--a common real-world requirement.
We saw that the core Ajax function made this a simple affair, particularly when we
only needed to grab a handful of form values.
The combination of the Form Plugin's
serializeForm()
method and the core
Ajax functions makes submitting all the controls in a form even easier. But even
easier than that, the Form Plugin makes submitting an entire form through Ajax
almost trivial with the
ajaxSubmit()
command.
This command, when applied to a wrapped set containing a form, grabs the
names and values of all the successful controls in the target form and submits
them as an Ajax request. We can supply information on how to make the request
Command syntax: resetForm
resetForm()
Calls the native reset() method of forms in the wrapped set
Parameters
none
Returns
The wrapped set


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

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