Ajax Ajax is not omnipotent, in the appropriate situation to use AJAX, in order to give full play to its strengths, improve system performance and user experience, can not be abused for technology. Ajax is characterized by asynchronous interaction, dynamic updating of Web pages, so its scope is more interactive, frequently read data Web applications. Now look at several examples of AJAX applications, and readers can learn how to use AJAX technology to improve existing Web applications.
Scenario 1. Data validation
When filling out a form's content, you need to guarantee the uniqueness of the data (for example, the user name that the new user registers), so you must validate the data entered by the user. There are usually two ways to validate data: one is to fill in directly, and then submit the form, this way need to submit this page to the server for verification, not only a long time and caused the server unnecessary burden; the second way is to improve the verification process, the user can click the corresponding verification button, Open a new window to see the results of the validation, but this requires a new browser window or dialog box, but also the need to write a validation of the page, compared to the cost of system resources. The use of Ajax technology, can be issued by the XMLHttpRequest object authentication request, based on the return of the HTTP response to determine whether the validation is successful, the entire process does not need to eject a new window, and do not need to submit the entire page to the server, fast without aggravating the server burden.
Scenario 2. Data on Demand
Classification trees or tree structures are used extensively in Web application systems, such as departmental structures, where document classification structures often use tree-shaped space rendering. The previous operation on the classification tree will cause the page overload, in order to avoid this situation, generally do not use every call back to the way, but the classification results in a one-time read the data and write the array, and then according to the user's operation, using JavaScript to control node rendering, This solves the operational response speed, does not duplicate the loading of the page, and avoids sending requests to the server frequently. However, if the user does not manipulate the classification or operate on only a subset of the data in the classification tree (which is very common), then there is a significant amount of redundancy in the data being read, which wastes the user's resources. Especially when the classification structure is complex and the data is huge, the disadvantage is more obvious.
Ajax is now used to improve the implementation mechanism of the classification tree. When the page is initialized, only the data of the first level subcategory is fetched and displayed; When the user points to the first node of the classification, the page requests all data of the two-level subcategory that the current category belongs to by using Ajax, and if you request a node of the two-level classification that has already been rendered, Again, request all data for the three-level subcategory to which the current taxonomy belongs, and so on. The page asks the server for the data it needs based on the user's actions, so there is no redundancy in the data and the total amount of data downloads is reduced. At the same time, when you update the page without overloading everything, only the part of the content that needs to be updated can be updated, which shortens the user's waiting time considerably relative to the way it was previously processed and overloaded.
Scene 3. Automatically update page
There are many changes in Web applications that are very fast, such as the latest hot news, weather forecasts, and chat room content. Prior to the advent of Ajax, users had to constantly refresh the page to see if there was a new content change, or the page itself would have the ability to refresh regularly, even if they knew the appropriate content (most chat room pages do this). It is possible that this will happen; there is a time when the content of the page has not changed, but the user does not know, still constantly refresh the page, or the user lost patience, gave up the Refresh page, but it is likely that there are new news, so that the first time to miss the opportunity to get information.
The application of Ajax can improve this situation, after the page load, through the AJAX engine in the background to a scheduled polling, send a request to the server to see if there is the latest news. If so, the new data (rather than all the data) is downloaded and dynamically updated on the page, notifying the user in a certain way (the ability to do this is the JavaScript's strength). This is to avoid the user to constantly manually refresh the page inconvenience, nor because of repeated refreshing the page caused by waste of resources.
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.