PHP development in combination with AJAX is backward, forward, and refresh | combined with AJA

Source: Internet
Author: User
Introduction Part 1 describes how to use Sajax, PHP, and JavaScript to develop basic albums. In the process of creating a history stack for a program, we will attach the client technique and associate it directly with Part 1 of the code. This article assumes that Introduction

Part 1 describes how to use Sajax, PHP, and JavaScript to develop basic albums. In the process of creating a history stack for a program, we will attach the client technique and associate it directly with Part 1 of the code. This article assumes that the reader understands JavaScript and browser cookies.

   Retained in the browser

When surfing the Internet, it is always from one page to another, from one site to another. In this process, the Web browser faithfully records the historical records of where you were, and creates a breadcrumbs digital track, along this track, we can return to the starting point step by step. The back button allows you to return to your position before the previous action. In this sense, it is the undo button on the Web.

Web is a page-based media. The back and forward buttons in the browser toolbar direct the browser from one page to another. When Macromedia Flash went viral, developers and users found that Rich Internet Application (RIA) broke this pattern. Users can browse on several sites, and then log on to a Flash-based website to spend several minutes on it. When you click the back button, the game is over. The user did not return to the previous Flash site and did not know what the site was.

This is also the case for the complete Ajax-based website-RIA. A: websites that use users to interact with a page for multiple times are easily troubled by the back button or any history button (in this case ). The title of the forward and reload buttons is the same as that of the back button. The built-in internal history record mechanism of Web browsers is an unavoidable title. For security reasons, developers cannot modify browser history or any related buttons. There is also the availability title. Imagine how confusing the user might be if the back button suddenly prompts a mysterious warning or the user is sent to a new website.

   Build a history stack

Although the browser history cannot be changed, you can build a historical record for the application in RIA by yourself. Obviously, it should be removed from the browser's standard navigation tool to some extent, but as mentioned above, the rich utility program deviated from the Web page to the page's scale mode to a certain extent.

We will create a stack to manage historical event records of the exploitation program, that is, store a list and add elements at the end of the table. Stack is used to store data in the order of backward first-in-first-out (LIFO. Although the data at the top of the stack is not deleted during rollback, this model is very similar to our needs. In JavaScript, stacks can be managed using arrays.

There is also a pointer together with the stack, which allows us to determine the current position in the stack. When we click in the exploitation program, the new event is pressed into the top of the stack, and the pointer points to the last added element. When you click the back and forward buttons of the exploitation program, a new event is not added to the stack, but a pointer to the stack is moved. Think about what will happen in the history stack when the app moves back: The browser returns to the last page viewed, and the previously unavailable forward button suddenly becomes available. When you browse a new page, the forward button turns gray again. The elements retained later in the browser history will pop up the stack, and new events will be pushed to the top of the stack. We will reproduce this action in our own history stack.

Our goal is to create a set of available history buttons: back, forward, and refresh, as shown in 1.

 
Figure 1. the back, forward, and refresh history buttons are displayed on the left, and the unavailable status is displayed on the right.

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.