Professional Documents
Culture Documents
APPLICATIONS
WITH AJAX
1
BY
Live Search
Online Poll
Upload Example
Reading XML Data
Feedback Form
Throttling
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
// Get data from the server's response
}
}
The data sent back from a server can be retrieved with the
responseText property.
Now, we want to set the value of the "Time" input field
equal to responseText:
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
document.myForm.time.value=xmlhttp.responseText;
}
}
Another simple use case happens during the writing of an e-mail. Most of
the time, you'll be writing an e-mail to someone you know, so it's logical to
assume that the person is already in your address book. To help you out, it
may be wise to preload your address book in the background and offer
suggestions. This approach is taken by many web-based e-mail systems,
including Gmail and AOL Webmail.
The key, once again, is the "logical-to-assume" criterion. By anticipating
and pre-loading information related to the user's most likely next steps,
you can make your application feel lighter and more responsive; by using
Ajax to fetch information related to any possible next step, you can quickly
overload your server and make the browser bog down with extra processing.
As a rule of thumb, only pre-fetch information when you believe it's logical
to assume that information will be requisite to completing the user's next
request.
Predictive Fetch is one pattern for retrieving data from the server; the other
side of an Ajax solution is the sending of data to the server.
Since you want to avoid page refreshes, the question of when to send user
data is important. In a traditional web site or web application, each click
makes a request back to the server so that the server is always aware of what
the client is doing.
In the Ajax model, the user interacts with the site or application without
additional requests being generated for each click.
Using Submission Throttling, you buffer the data to be sent to the server on
the client and then send the data at predetermined times. The venerable
Google Suggest feature does this brilliantly. It doesn't send a request after
each character is typed.
Instead, it waits for a certain amount of time and sends all the text
currently in the text box. The delay from typing to sending has been fine-
tuned to the point that it doesn't seem like much of a delay at all.
Submission Throttling,
Prof. Rama Satish, RNSIT, Bengaluru. in part, gives Google Suggest its speed. 19/08/2014
42
51
BY