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?
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 work.. You need call this function where you need get the parameter by passing its name..
|
|||||
|
Get all querystring parameters including checkbox values (arrays). Considering the a correct & normal use of GET parameters the things i see it's missing, on most functions, is the support for arrays and removing the hash data So i wrote this function
Using shorthand operators & while-- loop the performance should be very good to. Support:
Notes: It does not support object arrays (key[key]=value) If the space is + it remains a +. add Usage:
Return:
Demo: Info If you don't understand something or you can't read the function just ask i'm happy to explain what i did here. If you think the function is unreadable and unmanainable i'm happy to rewrite the function for you , but consider that shorthand & bitwise operators are always faster than a standard syntax (mybe read about shorthands and bitwise operators in the ECMA-262 book or us your favorite searchengine).Rewriting the code in a standard readable syntax means performance loss. |
||||
|
Simple Solution with Plain JS and Regex
|
||||
|
This didn't work for me, I want to match `?b' as the 'b' parameter is present, and not match '?return' as the 'r' parameter, here is my solution.
|
||||
|
The shortest possible expression in terms of size to obtain a query object seems to be:
You can make use of the
|
||||
|
quick, easy, and fast: The Function:
Usage:
|
||||
|
For those who wants a short method (with limitations):
|
|||||||||||||
|
Here is String prototype implementation:
Example call:
|
||||
|
Here's an extended version of Andy E's linked "Handle array-style query strings"-version. Fixed a bug ( It will handle the following querystring...
...making it into an object that looks like...
As you can see above, this version handles some measure of "malformed" arrays, i.e. -
It seems the jury is somewhat out on repeated keys as there is no spec. In this case, multiple keys are stored as an (fake)array. But do note that I do not process values based on commas into arrays. The code:
|
||||
|
Amazing how many overly complicated and incomplete solutions are posted here. Here's what I'm using:
Works with following URLs (values of
Returning 'override' rather than '0' in the last case makes it consistent with PHP. Works in IE7. |
|||||||||
|
Most pretty but basic:
It doesn't handle values lists such as |
||||
|
|
||||
|
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.
|
|||||
|
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.
Would you like to answer one of these unanswered questions instead?