SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax page - back button

    I have a page which makes an ajax request and in the response is a link. If I click a link, then press "back", how do I avoid having the all of the ajax requests restart, and instead just take them back to how it was when they left? I'm having a mind blank.. I know this is a common issue...
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2007
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The trick is to play with the history javascript object.
    I never did this, but remember having read about it.

    For each action, you add a new history step via js to the browser, and you store the the state of the page somewhere.
    On the back/forward events, you will be able to replay the actions.

    I've found this
    http://www.onjava.com/pub/a/onjava/2...ck-button.html
    and it seems related, but I don't have the courage to read it now.
    My bed's is calling me....

  3. #3
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The thing is, i'm not looking for "Back" to go back within the same page.. im actually going to another page, then clicking back to go back to the previous, different page... except it "restarts" the ajax calls and such..
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically, your javascript needs to be able to take itself back to the proper page state when the page loads. You would probably want to store a page state identifier as part of the #hash property in the url, and have javascript look at it, and then do whatever it needs to do to take itself to that page state.

    You could also store the state data as a cookie, but then this will break when a user opens multiple browser windows to the same ajax page.

  5. #5
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But when I go back and try to restore the state, i still have to re-make all the ajax requests, etc. no?
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  6. #6
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've found what I want to "copy", I just don't see exactly how they're doing it!

    http://www.apple.com/ca/search/?q=ipod (Interestingly, the Apple US search does NOT function this way and does in fact "do a new search" on back button)

    The search results are fetched via AJX. Click on a link, then hit your back button. The results and everything are all there immediately. No new request or anything. It also remembers any of the sections you have collapsed.

    Looking through their code as we speak, but is anyone able to provide some insight?
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried opera, FF3, IE7.

    The back button causes a new ajax request to be sent.
    It does not remember my place in the pagination.
    It does not remember which menus I had collapsed(neither the blue bars, nor the categories in the two boxes on the right).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •