Skip to content

Instantly share code, notes, and snippets.

@flisky
Forked from oomlaut/parseQuerystring.jquery.js
Created January 26, 2012 09:44
Show Gist options
  • Save flisky/1681990 to your computer and use it in GitHub Desktop.
Save flisky/1681990 to your computer and use it in GitHub Desktop.
add support to same key occurred multi times
jQuery.extend({
parseQuerystring: function(){
var nvpair = {};
var qs = window.location.search.replace('?', '');
var pairs = decodeURI(qs).split('&');
$.each(pairs, function(i, v){
var pair = v.split('=');
var key = pair[0], value = pair[1];
if(key in nvpair){
if(!$.isArray(nvpair[key])){ nvpair[key] = $.makeArray(nvpair[key]);}
nvpair[key].push(value);
} else {
nvpair[key] = value;
}
});
return nvpair;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment