Ajax combat: Four basic principles of Ajax

Source: Internet
Author: User
Tags sessions

Many of the frameworks we use have solidified the traditional web-based application pattern, and these application patterns have been deeply embedded in our minds. We spend a few minutes revealing which core concepts we need to rethink and how to rethink them from an AJAX perspective.

The browser is an application rather than a content

In traditional web-based Web applications, browsers play the role of Dumb terminals [7]. It does not know what stage the user is in the operating process. All of this information is stored on the server, specifically, on the user's session. Today, server-side user sessions have long been commonplace. If you use Java or. NET programming, server-side user sessions are part of the standard API-as well as Request, Response, MIME types-and they are simply unthinkable without them. Figure 1-11 depicts the typical lifecycle of traditional Web applications.

When a user logs on or otherwise initializes a session, several server-side objects are created. For example, an E-commerce-type web site needs to create an object that represents a shopping cart as well as a user's identity certificate. At the same time, the homepage of the browser site is presented to the user, which consists of the template file and the data and content specific to that user, such as the list of items that the user has recently browsed.

Each time the user interacts with the server, they get another document. In this document, the other template files and data that are included are the same except for the user-specific data. Browsers always faithfully discard old documents and display new documents because they are dumb terminals and do not know what else to do.

When the user chooses to exit or closes the browser, the application exits and the session disappears. This time the persistence layer will store the information the user needs to display after the next login. Ajax, in contrast, moves part of the application logic from the server side to the browser side, as depicted in figure 1-12.

Figure 1-11 The life cycle of traditional Web applications. All States of the user and the application session remain on the Web server. The user sees in the session is a series of pages, each page switch inevitably to go to the server to walk a back and forth

Figure 1-12 The life cycle of AJAX applications. After the user logs in, the server delivers a client to the browser. This application can handle a lot of user interaction independently, the application will send the request to the server in the background, without interrupting the user's operation process.

When a user logs on, the server delivers a much more complex document to the browser, which contains a lot of JavaScript code. This document will be associated with the user throughout the lifetime of the session. In this process, as the user interacts with it, its appearance can vary considerably. It knows how to respond to user input, whether it's up to you to either process it yourself or pass it to the Web server (the Web server accesses the database or other resources), or you can do it in a combination.

Because this document exists throughout the user's session, it can save the state [8]. For example, the contents of a shopping cart can be saved in a browser rather than in a server session.

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.