Created
November 21, 2009 04:00
-
-
Save marciobarrios/239987 to your computer and use it in GitHub Desktop.
para transformar los parametros de una url en un objeto
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
/* | |
we have: | |
http://foo.com?nodeId=2&userId=3&sortOrder=name&sequence=asc | |
we want: | |
var params = { | |
nodeId : 2, | |
userId : 3, | |
sortOrder: name, | |
sequence: asc | |
} | |
*/ | |
var url = location.search; | |
url = url.replace('?', ''); | |
var queries = url.split('&'); | |
var params = {}; | |
for(var q in queries) { | |
var param = queries[q].split('='); | |
params[ param[0] ] = param[1]; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment