Information Technology Reference
In-Depth Information
so that other options can be customized based on it). In this case one might disable or
hide all subsequent form fields, then wait until the request is returned; if it is successful,
the fields could then be re-enable or shown. But be mindful that your entire script will be
held up, so doing this with larger amounts of data will not be a good idea. One could
imagine the entire browser “stuck,” something frustrating on any platform, but especially
vexing on a mobile device where the demand for speed is already greater than its
availability.
Also be aware that if you decide to set asynchronous to false, you don't need (and
shouldn't use) the onreadystatechange function. This is because there is no ready state
to look for—the code will continue processing after the request is ready. Simply put the
rest of your JavaScript code after the send function, and it will process sequentially.
Finally, before setting asynchronous to false, you may wish to ask yourself if AJAX is
really the best solution for what you're trying to accomplish. Sure, it will probably look
cool, but if you need to force the user to wait for something, perhaps it would be easier
to implement your code in a different way. For example:
If there is the possibility that your users may disable JavaScript,
requiring JavaScript to complete a form will render the page useless
for them. Using AJAX with asynchronous set to true will generally
avoid this problem.
A long form that requires complex validation (e.g., database lookups)
after several options might work better as a multi-page form, allowing
users to create an account on page one, and then return to
subsequent pages at their leisure. Each page could save the progress
of the form, allowing users to jump back in where needed, while also
providing adequate validation.
Given these thoughts and your own experience in testing, you'll be able to get an idea
about not only the best form submission method, GET or POST, but also about whether
using the uncommon method of setting asynchronous to false is a good idea for your
script.
Summary
In this chapter we've taken a big step forward in making our users' lives easier. We've
started doing some of the processing on our forms or our pages in the background, so
that users do not need to refresh pages, submit forms, or reload content needlessly. By
implementing the ideas and concepts outlined here across your projects and even in our
previous examples, you'll be able to create awesome “supercharged” designs in no
time!
 
Search WWH ::




Custom Search