I"d like to hear critiques on the following method for dealing with the
back button and bookmarkability problem with AJAX. Whenever I do
something on a page with ajax, I add to document.location.hash (which
doesn't reload the page but does include the parameters in a bookmark)
like so:
document.location.hash = document.location.hash + '¶m=value';
So the URL gets updated like so:
http://host.com/cgi-bin/foo.cgi?cmd=bla#¶m=value;
When that page is loaded from that bookmark, I'm converting that
information in the hash to the query (which reloads the page with those
parameters in the URL and drops the hash):
var hash = document.location.hash.substr(2);
if (hash.length > 0){
var searchadd = '';
var elements = hash.split('&');
for (i=0;i<elements.length;i++){
searchadd = searchadd + '&' + elements[i];
}
document.location.href=document.location.pathname +
document.location.search + searchadd;
}
Is it correct that the hash (i.e. everything after the # in the URL) is
only available client side?
The reload to incorporate those parameters in the URL is time consuming.
It takes an additional 60-90 seconds over a URL that doesn't need to be
corrected. Is there a better way?