Friday, April 8, 2011

problem with ajax( page refresh)

hi im using ajax to extract all the pages into the main page but am not being able to control the refresh , if somebody refreshes the page returns back to the main page can anybody give me any solutions , i would really appreciate the help...

From stackoverflow
  • You can rewrite the current url so it gives pointers to where the user was - see Facebook for examples of this.

  • you could add anchor (#something) to your URL and change it to something you can decode to some particular page state on every ajax event.

    then in body.onload check the anchor and decode it to some state.

    back button (at least in firefox) will be working alright too. if you want back button to work in ie6, you should add some iframe magic.

    check various javascript libraries designed to support back button or history in ajax environment - this is probably what you really need. for example, jQuery history plugin

    miceuz : you should definately check our jQuery if you are going to realt of javascript. very handy to use, but not much helpful in terms of learning javascript in depth..
  • I always store the 'current' state in PHP session.

    So, user can refresh at any time and page will still be the same.

  • if somebody refreshes the page returns back to the main page can anybody give me any solutions

    This is a feature, not a bug in the browser. You need to change the URL for different pages. Nothing is worse then websites that use any kind of magic either on the client side or the server side which causes a bunch of completely different pages to use the same URL. Why? How the heck am I gonna link to a specific page? What if I like something and want to copy & paste the URL into an IM window?

    In other words, consider the use cases. What constitutes a "page"? For example, if you have a website for stock quotes--should each stock have a unique URL? Yes. Should you have a unique URL for every variation you can make to the graph (i.e. logarithmic vs linear, etc)? Depends--if you dont, at least provide a "share this" like google maps does so you can have some kind of URL that you can share.

    That all said, I agree with the suggestion to mess with the #anchor and parse it out. Probably the most elegant solution.

0 comments:

Post a Comment