Notes-Shows AJAX-acquired data from the previous page when returning to the previous page

Source: Internet
Author: User

Note The first part: http://www.cnblogs.com/zczhangcui/p/6869219.html

In the first part of the problem is that after using Ajax to obtain a series of list information, stitching good HTML inserted into the original page, similar to a series of news list, click to view the details and then return to this page, there will be all Ajax get and insert the page structure is not, after investigation, Decide to try to start with the history object.

I used the History.replacestate method to change the state of the current page, and each time Ajax gets the information, it puts the contents of the page that you want to keep in the state, and when it returns to this page, reads the information in the state, and if state is not null, the page in state Structure shows up.

The procedure is simple and takes about two steps:

1. After Ajax gets the information and assembled it into the HTML structure, put the HTML structure you want to keep in the state

History.replacestate ({current_html: $ ('. Page '). html ()}, ', ');

Some of the necessary and not very important information can be saved in the HTML of a place, need to use the time to read again. For example, I keep the current page information in HTML so that when I go back to the pages, I can read the pages and request the next page through Ajax.

2. When you return to this page, check to see if the state holds any information, and if so, show it.

var prev_html = history.state && history.state.current_html; if (prev_html) {    $ ('. Page '). html (prev_html);}

This basically implements the information that is obtained from the previous Ajax request after the return is still displayed.

But after trying to use it and finding another problem, I rolled to somewhere in the middle of the page, clicked on one of the pages to go to the details page, and then I clicked back to return to this page, although it was still the previous structure, but it didn't scroll to where I browsed before.

Finally, my solution is to go to the details page, temporarily save a browse location in the Sessionstorage information, the implementation of a small bug, and then see if there is a better way.

Notes-Shows AJAX-acquired data from the previous page when returning to the previous page

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.