A
A
Alexander2016-01-17 13:40:28
PHP
Alexander, 2016-01-17 13:40:28

How to correctly pass get-parameters and conveniently work with Url in js?

Hey!
There is a typical online store with product filtering by different parameters/criteria.
I started doing something like this:
site.ru/cat/?param=102,105,204&view=1&sort=asd
But when changing (on/off) some parameter, you need to parse the URL, parse the parameters (comma-separated), rebuild the URL, which seems to me pretty boring job.
Now I came across that some people pass parameters in an array:
site.ru/cat/?param[]=102¶m[]=105¶m[]=204&view=1&sort=asd
Which approach is correct? Advise how similar tasks on the client are correctly solved?
PS I found js libraries for URL parsing, for example https://github.com/Mikhus/jsurl
But they don't work with arrays (param[] - such parameter names are not supported).
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-01-17
Protko @Fesor

param[] - such parameter names are not supported

Well, because it's an invalid thing. It only works in PHP and nowhere else. Instead, you should use a delimiter
/cat/?param=102,105,204&view=1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question