Ajax and URLs

February 1, 2007, 5:44 pm
I know this solutions exists but doubt whether its existence is ubiquitous. The Wikipedia article on Ajax [ http://en.wikipedia.org/wiki/Ajax_(programming) ] mentions it in 'Cons'.

Straight to the point. One very common problem with ajax->dynamically updated pages is that, since content is fetched and updated within the page itself, the original webpage url doesn't change and hence it is impossible to bookmark/remember them.

For example, the video comments on youtube. If a video has ten pages of comments, when clicking the page numbers, the comments are updated dynamically without the url ever changing. So what if you want to bookmark page no:9 ? Not possible.

The simplest solution is to make use of the 'url fragment identifier' or whatever that comes after the # in a url. eg: http://something.com/page#here-it-goes

Javascript can update the fragment identifier dynamically with a simple

CODE:
document.location.href = '#whatever';


On page load, something like RegEx could be used to parse the query

CODE:
var thisUrl = document.location.href;
var query = thisUrl.split('#');
alert(query[1]);


So if page numbers or required variables are set as the fragment identifiers, it is possible to efficiently make Javascript process it (nearly) and make Ajax act normal with page urls.
Page :  1