views:

382

answers:

4

I need a solution for the page refresh and the back button when using AJAX.

I'm using simple javascript for the AJAX implementation.

If anybody could send a code snippet I would be very grateful.

+5  A: 

If you're using jQuery, there's the history plugin.

Chad Birch
Nice answer, is it possible to do this same without the jquery?
praveenjayapal
Anything doable with jQuery is possible without, by looking through the plugin source you may be able to figure out what techniques they're using to do it.
Chad Birch
+1  A: 

essentially, you need to use & monitor the hash portion of the url...

http://.../path?parms#hashpart

Whan you change the hash, iirc window.location.hash , it won't reload the page, but your ajax can monitor, and respond to it.

Tracker1
+2  A: 

I am working on this, see my question, the link in the 'update' text.

KooiInc
Very much perfect example, i like this.
praveenjayapal
A: 

The onbeforeunload event can be useful to guard against refreshing but it fires if you navigate away or refresh. If you require that users login to the app you can always show a generic message advising against navigating away and refreshing. If users click your app log out button set a var to disable the warning. Could probably also make a 'Close' button that does the same thing.

sjbotha