-
-
Save timvasil/5210649 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* $.parseParams - parse query string paramaters into an object. | |
*/ | |
(function($) { | |
var re = /([^&=]+)=?([^&]*)/g; | |
var decode = function(str) { | |
return decodeURIComponent(str.replace(/\+/g, ' ')); | |
}; | |
$.parseParams = function(query) { | |
var params = {}, e; | |
if (query) { | |
if (query.substr(0, 1) == '?') { | |
query = query.substr(1); | |
} | |
while (e = re.exec(query)) { | |
var k = decode(e[1]); | |
var v = decode(e[2]); | |
if (params[k] !== undefined) { | |
if (!$.isArray(params[k])) { | |
params[k] = [params[k]]; | |
} | |
params[k].push(v); | |
} else { | |
params[k] = v; | |
} | |
} | |
} | |
return params; | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment