terrid25
terrid25

Reputation: 1946

AJAX and using javascript history()

I have page, that loads in data using AJAX (a form filter) using jQuery. This then gives me a list of items that I click on.

When the page of the item loads, I have a back button, using:

 <script type="text/javascript">
 function navigateBack(){
  if (document.referrer.indexOf("press")> -1){
   history.go(-1);
   return false;
  }
  return true;
 }
 </script>
     <a href="" onClick="navigateBack()">

But what I'd really like to happen, is that it returns to the AJAX filtered results.

Is this possible?

Thanks

Upvotes: 0

Views: 1285

Answers (2)

Vinod R
Vinod R

Reputation: 1216

This requirement has to be implemented such that we have a key appended to the URL like

http://abc.com/xyz.html#search-key=keyword

In the java script it should have a global (like static) variable which is a map of objects for the search results for various keys. If the map contains the key in the url then return form the map else fire an ajax request and fetch the value from server.

Be sure to append the url with the key whenever there is a server call made and the result is stored in a map. Some frameworks like DWR make it very simple to handle.

Upvotes: 1

RichieHindle
RichieHindle

Reputation: 281835

A good way to control the Back button in an AJAX application is by using the Real Simple History library.

"RSH serializes application data in an internal JavaScript cache so that bookmarks and the back button can be used to return your application to an earlier state."

Upvotes: 0

Related Questions