Created
April 23, 2013 15:54
-
-
Save netsuite/5444832 to your computer and use it in GitHub Desktop.
js: Get JSON object from a URL
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
// url = "http://localhost/index.php?module=search¶m1=4"; | |
function jsonObjFromURL (url){ | |
var parameters = url.split("?"), | |
jsObject = {}, | |
jsObjectParams = {}, | |
paramPair; | |
jsObject.baseURL = parameters[0]; | |
var paramPairString = parameters[1].split("&"); | |
for (var i = paramPairString.length - 1; i >= 0; i--) { | |
paramPair = paramPairString[i].split("="); | |
jsObjectParams[paramPair[0]] = paramPair[1]; | |
} | |
jsObject.params = jsObjectParams; | |
return JSON.stringify(jsObject); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment