admin管理员组

文章数量:1355151

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 pletely 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.

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 pletely 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.

Share Improve this question edited Sep 18, 2010 at 10:04 balupton 48.8k32 gold badges134 silver badges184 bronze badges asked Jun 22, 2009 at 22:03 dougoftheabacidougoftheabaci 1
  • some related questions: stackoverflow./questions/946582/… stackoverflow./questions/974186/… stackoverflow./questions/973845/saving-history-in-ajax stackoverflow./questions/680785/… stackoverflow./questions/940964/… stackoverflow./questions/629765/… – Christoph Commented Jun 22, 2009 at 22:22
Add a ment  | 

5 Answers 5

Reset to default 3

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

This would be the answer I would put here:

Browser back button and dynamic elements

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.

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

  • How to show Ajax requests in URL?
  • How does Gmail handle back/forward in rich JavaScript?

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 plete ajax websites while being pletely unobtrusive and gracefully degradable).

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.

本文标签: javascriptWhen using back button AJAX results have been lostStack Overflow