Ajax application scenarios

Source: Internet
Author: User
Content from Internet: http://del.icio.us/cnbruce/ajax

Ajax is not omnipotent. Ajax can be used to give full play to its strengths, improve system performance and user experience, and cannot be abused for technical purposes. Ajax is characterized by Asynchronous interaction and dynamic updating of web pages. Therefore, it is applicable to Web applications that have many interactions and frequently read data. Now let's take a look at several Ajax application examples. Readers can learn how to use Ajax technology to improve the existing web application system.

Scenario 1. Data Verification

When entering the form content, you must ensure the uniqueness of the data (such as the username entered by the new user registration). Therefore, you must perform data verification on the content entered by the user.

There are two methods for data verification:

One is to directly fill in and then submit the form. In this way, the page needs to be submitted to the server for verification. The whole process is not only long, but also creates unnecessary burden on the server;

The second method is to improve the verification process. You can click the corresponding verification button to open a new window to view the verification result. However, you need to open a new browser window or dialog box, you also need to write verification pages to consume system resources.

With Ajax technology, the XMLHTTPRequest object can send a verification request and determine whether the verification is successful Based on the returned HTTP response. A new window does not need to be popped up or the entire page is submitted to the server, fast without increasing the server load.

Scenario 2. Retrieve data as needed

The classification tree or tree structure is widely used in Web application systems. For example, the Department structure and document scoring class structure are usually presented in a tree space.

In the past, every operation on the category tree would cause page overloading. In order to avoid this situation, we generally do not use the background method every time we call it, instead, the data in the classification results is read at one time and written into the array. Then, based on the user's operations, JavaScript is used to control the node rendering. This solves the operation response speed, do not load pages repeatedly and avoid frequent requests to the server. However, if you do not perform operations on a category or only perform operations on a portion of the data in the category tree (this is common ), therefore, the read data will have a considerable amount of redundancy, which wastes user resources. Especially when the classification structure is complex and the data size is large, this disadvantage is even more obvious.

Now, Ajax is used to improve the implementation mechanism of the classification tree. On the initialization page, only the data of the first level of sub-category is obtained and displayed. When a user clicks the first point of the first level of classification, the page uses ajax to request all data of the second-level subcategory to which the current category belongs. If you request a node of the second-level subcategory that has already been presented, request all data of the third-level subcategory to the server again, and so on. The page will request the data required by the server based on the user's operations, so that there will be no data redundancy, reducing the total amount of data downloads. At the same time, you do not need to reload all the content when updating the page. You only need to update the part of the content that needs to be updated. Compared with the background processing and reload method, this greatly shortens the waiting time of users.

Scenario 3. automatically update the page

There is a lot of rapid data changes in Web applications, such as the latest hot news, weather forecasts, and chat room content. Before Ajax appears, you must refresh the page to check whether any new content changes, even if you know the corresponding content, or the page itself implements the timed refresh function (this is what most chat room pages do ).

This may happen. For some time, the content of the webpage has not changed, but the user does not know it and continues to refresh the page; or the user has lost patience and gave up refreshing the page, but it is very likely that there will be new messages here, thus missing the opportunity to get the message as soon as possible.

The Application of AJAX can improve this situation. After a page is loaded, the Ajax engine regularly polls the page in the background and sends a request to the server to check whether there is any latest message. If yes, download new data (rather than all data) and dynamically update the data on the page to notify users in a certain way (implementing such a function is exactly the strength of JavaScript ).

This avoids the inconvenience of manual page refresh and does not waste resources because of repeated page refresh.

Now that you are interested in Ajax, you need to know the important point, that is, when and when Ajax technology should be used. First, do not be afraid to try new methods in the application. We believe that almost every web application can benefit from Ajax technology, but it should not be too outrageous. It is appropriate from the beginning of verification, but do not restrict your initiative. Of course you can use ajax to submit data, but you may not use it as the main method for submitting data.

Secondly, the only thing that will affect your application of AJAX is the browser issue. If a large number of users (or especially important users) are still using older browsers, such as IE 5, Safari 1.2, or earlier versions of Mozilla 1.0, Ajax technology will not work. If this is an important user, you need to use a cross-browser method for the target user, instead of Ajax, or develop a website that can be properly downgraded. Browser support may not be an important factor because Netscape navigaxar 4 has a small market share. However, you should check Web logs to see what technologies your application applies.

As mentioned above, verification and form filling are very suitable for Ajax implementation. You can also use Dom's drag technology to build truly dynamic websites, such as Google's personalized homepage.

As you can see, Ajax provides a new opportunity for Web application development. You will no longer be hindered by previous proprietary technologies or technical trade-offs. With Ajax, the boundaries between fat customers and thin customers are no longer distinct. The real winner is your users.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.