5

So I've set up a pagination system similar to Twitter's where where 20 results are shown and the user can click a link to show the next twenty or all results. The number of results shown can be controlled by a parameter at the end of the URL however, this isn't updated with AJAX so if the user clicks on one of the results and then chooses to go back they have to start back at only 20 results.

One thought I've had is if I update the URL when while I'm pulling in the results with AJAX it should—I hope—enable users to move back and forth without losing how many results are shown.

Is this actually possible or have I got things completely wrong?

Also, how would I go about changing the URL? I have a way to edit the URL with javascript and have it be a variable but I'm not sure how to apply that variable to the URL.

Any help here would be great!

A side note: I'm using jQuery's load() function to do all my AJAX.

balupton
  • 47,113
  • 32
  • 131
  • 182
  • some related questions: http://stackoverflow.com/questions/946582/browser-back-button-and-dynamic-elements http://stackoverflow.com/questions/974186/managing-browser-history-in-ajax http://stackoverflow.com/questions/973845/saving-history-in-ajax http://stackoverflow.com/questions/680785/on-window-location-hash-change http://stackoverflow.com/questions/940964/could-a-page-display-diferrent-content-if-the-url-hash-changes http://stackoverflow.com/questions/629765/enabling-back-fwd-key-events-for-an-ajax-application – Christoph Jun 22 '09 at 22:22

5 Answers5

3

Not mentioned in the duplicate threads, but useful nonetheless: Really Simple History (RSH).

ajm
  • 19,795
  • 3
  • 32
  • 37
2

This would be the answer I would put here:

Browser back button and dynamic elements

Community
  • 1
  • 1
karim79
  • 339,989
  • 67
  • 413
  • 406
1

You can't actually change the url of the page from javascript without reloading the page.

You may wish to consider using cookies instead. By setting a client cookie you could "remember" how many results that user likes to see.

A good page on javascript cookies.

Joel
  • 19,175
  • 2
  • 63
  • 83
  • Nowadays, it's possible to change the URL without reloading, see http://stackoverflow.com/questions/3338642 – Daniel Naber Aug 09 '13 at 14:03
  • True. Since this answer is no longer accurate I'm not sure what the correct SO action would be. Update it with more info? – Joel Aug 09 '13 at 17:05
1

The answer for this question will be more or less the same as my answers for these questions:

In summary, two projects that you'll probably want to look at which explain the whole hashchange process and using it with ajax are:

  • jQuery History (using hashes to manage your pages state and bind to changes to update your page).

  • jQuery Ajaxy (ajax extension for jQuery History, to allow for complete ajax websites while being completely unobtrusive and gracefully degradable).

Community
  • 1
  • 1
balupton
  • 47,113
  • 32
  • 131
  • 182
-3

First 3 results google returns:
first
second
third

I'll eat my shorts if none of them are useful. ^^

And yeah - you can't change URL through JS.

Community
  • 1
  • 1
Arnis Lapsa
  • 45,880
  • 29
  • 115
  • 195