Created
July 6, 2016 16:34
-
-
Save hoggren/7ae6523eacf8b40b7efa6c4e0fe65504 to your computer and use it in GitHub Desktop.
Parse querystring javascript
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
var parseQuery = function(uri) { | |
var query = {}; | |
var uri = uri.split('?'); | |
if(uri.length == 0) return null; | |
var rawQuery = decodeURIComponent(uri[1]); | |
rawQuery = rawQuery.split('&'); | |
if(rawQuery.length == 0) return null; | |
for (var i = 0; i < rawQuery.length; i++) { | |
var keyValue = rawQuery[i].split('='); | |
query[keyValue[0]] = keyValue[1]; | |
} | |
return query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment