Is there a plugin-less way of retrieving query string values via jQuery (or without)?
If so, how? If not, is there a plugin which can do so?
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
Is there a plugin-less way of retrieving query string values via jQuery (or without)? If so, how? If not, is there a plugin which can do so? |
|||||||||||||||||||||
locked by animuson♦ Jul 25 '14 at 19:35This question's answers are a collaborative effort: if you see something that can be improved, just edit the answer to improve it! No additional answers can be added here |
|||||||||||||||||||||
|
This will parse variables AND arrays from a URL string. It uses neither regex or any external library.
Example:
Output:
|
||||
|
The shortest possible expression in terms of size to obtain a query object seems to be:
You can make use of the
|
||||
|
This will work... You need to call this function where you need get the parameter by passing its name...
|
|||||
|
Quick, easy, and fast: The function:
Usage:
|
|||||||||
|
Use:
Please check and let me know your comments. Also refer to How to get querystring value using jQuery. |
|||||||||
|
Here is
Example call:
|
|||||||||
|
I recommend Dar Lessons as a good plugin. I have worked with it fo a long time. You can also use the following code.
Jus put
|
|||||||||
|
Doing this reliably is more involved than one may think at first.
To solve this, here is a configurable API with a healthy dose of defensive programming. Note that it can be made half the size if you are willing to hardcode some of the variables, or if the input can never include Version 1: Returns a data object with names and values for each parameter. It effectively de-duplicates them and always respects the first one found from left-to-right.
Version 2: Returns a data map object with two identical length arrays, one for names and one for values, with an index for each parameter. This one supports duplicate names and intentionally does not de-duplicate them, because that is probably why you would want to use this format.
} |
|||||||||||||
|
|
||||
|
This function will return a parsed JavaScript object with any arbitrarily nested values using recursion as necessary. Here's a jsfiddle example.
Given any of the above test examples.
|
|||||||||
|
A simple solution with plain JavaScript and regular expressions:
|
||||
|
See this post or use this:
|
|||||||||||||
|
This didn't work for me, I want to match
|
|||||||||
|
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?