Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: Change URL param without reloading?

I have a question, is it possible to change the URL via JQuery under the following conditions:

  • Same URL will load on browser back and on reloads
  • Page doesn't reload when you change the parameter
like image 908
Jan Meier Avatar asked Apr 25 '13 14:04

Jan Meier


2 Answers

If you wanna prevent the page from reloading you'll have to use hash "#"

And if you wanna change the URL try that:

jQuery.param.querystring(window.location.href, 'valueA=321&valueB=123');

This will return the following URL:

http://bla.com/test.html?valueA=321&valueB=123

like image 142
James Carter Avatar answered Oct 12 '22 01:10

James Carter


I may be wrong but I think the browser will do a post if you change the location.

So, could it help you to use a post instead than a GET and change a hiddenfield/just set the value?

You can use jQuery.ajax() to make calls to the server setting the values you need in the post (or get, as you wish). That way the url doesn't change and you make the requests you need.

like image 42
Ruben.Canton Avatar answered Oct 12 '22 03:10

Ruben.Canton