Is there any way to merge get parameters? - HTML / Javascript

often I find myself delighted with simple things, I’m not sure, but I believe that this may be one of them.

Often I need to combine get attributes, especially in filters and search pages on sites. . This is quite complicated, as you can remove and add parameters dynamically.

An easy way to do this is to use a form, but it becomes difficult when adding elements that are not in the form. e.g. pagination

For example, I might have a url like the following

http://www.example.org/ninja_search/?speed__gt=5&night_sight=1&page=1

How would I combine such a URL with page = 2, replacing 1 with a new value? Is javascript the only option?

? speed__gt = 5 & night_sight = 1 & page = 1 + page = 2 =? speed__gt = 5 & night_sight = 1 & page = 2

Thank:)

+3
source share
1 answer

The solution is to use []to explicitly create an array of parameters, supporting its server-side language:

speed__gt = 5 &? Night_sight = 1 <b> & page [] = 1 & page [] = 2

For example, if your server language is PHP, it $_GET['page']now returns an array with 1 as the first element and the second as the second.

You can also use this method in forms by applying it to an attribute name:

<form id="myform">
  <input type="hidden" name="page[]" value="1" />
  <input type="hidden" name="page[]" value="2" />
</form>

, - .

speed__gt = 5 &? Night_sight = 1 & = 1 & = 2

page 2, .

+3

Source: https://habr.com/ru/post/1755947/


All Articles