Created
May 25, 2013 08:06
-
-
Save coodoo/5648333 to your computer and use it in GitHub Desktop.
input: "$filter=&$top=3&$skip=3&$orderby=firstName&$format=json&$inlinecount=allpages output: Object {$filter: "", $top: "3", $skip: "3", $orderby: "firstName", $format: "json"…}
$callback: "callback"
$filter: ""
$format: "json"
$inlinecount: "allpages" optional: enter key name as 2nd parameter to just get that value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.extend({ | |
getQueryString: function ( urlString, key) { | |
function parseParams() { | |
var params = {}, | |
e, | |
a = /\+/g, // Regex for replacing addition symbol with a space | |
r = /([^&=]+)=?([^&]*)/g, | |
d = function (s) { return decodeURIComponent(s.replace(a, " ")); }, | |
q = urlString; | |
while (e = r.exec(q)) | |
params[d(e[1])] = d(e[2]); | |
return params; | |
} | |
if (!this.queryStringParams) | |
this.queryStringParams = parseParams(); | |
return key ? this.queryStringParams[key] : this.queryStringParams; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using regex for this is just wrong and will fail in some scenarios.
You'd better off using a tiny reusable module like:
https://github.com/sindresorhus/query-string