HTML5 Localstorage solves the pit of Ajax fallback

Source: Internet
Author: User

A page is loaded with Ajax data, and is a scrolling effect, when scrolling through a few screens, into the new link page B, and then return to a, the data of a page needs to be reloaded, from the beginning, the experience is very bad.

Solution: (1) hash;2) HTML5 's history characteristics, 3) Localstorage/cookie, and so on, Localstorage is the simplest, do not need to introduce other things, simple transformation can be achieved.

Reset page Environment function Resetstatus () {var oldstatus = Window.localStorage.getItem ("Goodstatus");            If the data is not stored locally, load the if (Oldstatus = = null) {LOADPDT () directly from the beginning;        Return        }//extract locally stored data var Oldjson = Json.parse (oldstatus);        page = Oldjson.page;            if (OldJson.kw.length > 0) {$ ("#search_input"). Val (oldjson.kw);            $ ("#search_text"). Hide ();        $ ("#search_cancel"). Show ();        } = Oldjson.order;        Ctgid = Oldjson.ctgid; -----------//something Todo//-----------//directly display the stored HTML to page $ ("#goodsList"). HTML (Window.lo        Calstorage.getitem ("Goodlist"));        Clear local data to prevent active refresh of Window.localStorage.removeItem ("Goodstatus");    Window.localStorage.removeItem ("Goodlist"); }//instead of a link before the direct jump way, the purpose is to store the data function Openpdtdetail (ID) {//Storage data Window.localStorage.setItem ("Goo Dstatus ", Json.stringify ({page:page, kw: $.trim($ ("#search_input"). Val ()), Order:orderby, ctgid:ctgid});        Window.localStorage.setItem ("Goodlist", $ ("#goodsList"). html ());    Window.location.href = "/mobile/goods/detail/" + ID + "[email protected][" Sid "]"; }

And found that there is a benefit, the HTML content will be displayed to the page, will automatically return to the original location, no need to re-locate.

HTML5 Localstorage solves the pit of Ajax fallback

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.