0

hi here is the problem: my url is like this http://somesite.com?theSearch=someword&a=b&c=d

on this page search results are displayed and on this page i have put the functionality of ajax search i.e. the results are updated without the page reload but the problem is if the user clicks on any link on the page and then presses the back button he results on the page page with the search results of "someword" not the new word typed (i mean the word for which the ajax results were updated) the client complains it and i need to fix it anyone have a solution?

i am using jQuery

1
  • this would do the trick w3.org/TR/html5/history.html , but its not available on much browsers at the moment (chrome comes to mind) Commented Dec 23, 2010 at 11:39

2 Answers 2

1

You can't change the location.href without a new load. What you can do is set the hash.

Every time you make a search change the hash

function doSearch(searchword) {
    location.hash = searchword;
    //your search code
}

Now the hash will refer to the latest search. And then add this code to "override" the get parameter ?theSearch=.

$(document).ready(function() {
    if(location.hash.length>0) {
        doSearch(location.hash);
    }
});

Its not a nice solution since you will load 2 search results, but it will work.

Sign up to request clarification or add additional context in comments.

Comments

0

You can try Sammy. It utilizes the URL hash (#) so you can create single page applications that still respond to the back button in your browser, just like facebook. And it runs on jQuery.

2 Comments

thankx buddy but it works with the "hash" part of the url and i need to change a part b/w url i can't re-factor the code becus i am near the deadline :( thanks for your help anyway
@user: You can't do what you want without changing the hash (or by changing the main part of the URL).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.