Skip to content

Instantly share code, notes, and snippets.

@netsuite
Created April 23, 2013 15:54
Show Gist options
  • Save netsuite/5444832 to your computer and use it in GitHub Desktop.
Save netsuite/5444832 to your computer and use it in GitHub Desktop.
js: Get JSON object from a URL
// url = "http://localhost/index.php?module=search&param1=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