0

I am looking for a nice way to redicrect in my page, after an Ajax request

If it succeeds I would like to transform the current uri (location.href)

http://my.domain.com/jm/app.html?application=test&keyword=pp&data=&enum=&end=

into

http://my.domain.com/jm/app.html#Results?application=test&keyword=pp&data=&enum=&end=

So adding #Results after uri path, but I would like to preserve the query string, It's probably ugly to find a regex for that, and apply it to location.href

Is there a jquery method to just browsing inside page?
like

$.redirectTo("Results")
1
  • 2
    Why not just update location.hash? Commented Apr 28, 2012 at 15:47

2 Answers 2

2

Have you looked at the location.hash property?

As a side note, this plugin has come in really useful for detecting a change in the hash, and then reacting on it. jQuery hashchange

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

Comments

0

I would suggest using History.js or jQuery BBQ. They both provide good support for HTML5 pushState with a fallback for HTML4 browsers (using a hash similar to your example). jQuery BBQ has some nice functions for manipulating the query string, as well.

Here's the basic idea (using History.js). On success, you update the location like this:

var newUrl = "/app.htmlapplication=test&keyword=pp&data=&enum=&end=";

// Make AJAX request ...

// On success
History.pushState({}, null, newUrl);

You will also want to implement a listener for state/hash change events. Using History.js, it looks something like this:

History.Adapter.bind(window, 'statechange', function() {
    // The user probably hit the back button, do something...
});

I kept my examples pretty short, so give a quick look at the documentation for each plugin and see which one fits your project best.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.